104 lines
3.7 KiB
PHP
104 lines
3.7 KiB
PHP
<?php
|
|
// Questo file può essere vuoto o contenere logica PHP aggiuntiva se necessario
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Autenticazione e Recupero Clienti VisualLims</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
max-width: 600px;
|
|
margin: 20px auto;
|
|
padding: 20px;
|
|
}
|
|
|
|
#authButton {
|
|
padding: 10px 20px;
|
|
background-color: #007bff;
|
|
color: white;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
#authButton:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
|
|
#result {
|
|
margin-top: 20px;
|
|
padding: 10px;
|
|
border: 1px solid #ccc;
|
|
word-wrap: break-word;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>Autenticazione e Recupero Clienti VisualLims</h1>
|
|
<button id="authButton">Autentica e Recupera Clienti</button>
|
|
<div id="result"></div>
|
|
|
|
<script>
|
|
document.getElementById('authButton').addEventListener('click', async () => {
|
|
const resultDiv = document.getElementById('result');
|
|
resultDiv.textContent = 'Autenticazione e recupero clienti in corso...';
|
|
|
|
try {
|
|
// Step 1: Autenticazione
|
|
const authResponse = await fetch('auth_proxy.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
}
|
|
});
|
|
|
|
const authData = await authResponse.json();
|
|
if (!authResponse.ok) {
|
|
throw new Error(`Errore HTTP durante autenticazione! Stato: ${authResponse.status}, Dettagli: ${authData.error || JSON.stringify(authData)}`);
|
|
}
|
|
|
|
// Estrai il token
|
|
let token;
|
|
if (authData.token && typeof authData.token === 'string' && authData.token.length > 0) {
|
|
token = authData.token;
|
|
} else {
|
|
throw new Error(`Autenticazione fallita: Nessun token valido ricevuto. Dettagli: ${JSON.stringify(authData)}`);
|
|
}
|
|
|
|
// Step 2: Recupero elenco clienti
|
|
const clientiResponse = await fetch(`https://93.43.5.102/limsapi/api/odata/Cliente`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`,
|
|
'Accept': 'application/json',
|
|
'User-Agent': 'Mozilla/5.0 (compatible; PHP cURL)'
|
|
}
|
|
});
|
|
|
|
const clientiData = await clientiResponse.json();
|
|
if (!clientiResponse.ok) {
|
|
throw new Error(`Errore HTTP durante recupero clienti! Stato: ${clientiResponse.status}, Dettagli: ${clientiData.error || JSON.stringify(clientiData)}`);
|
|
}
|
|
|
|
// Mostra l'elenco dei clienti
|
|
if (clientiData && clientiData.value && clientiData.value.length > 0) {
|
|
const clientiList = clientiData.value.map(cliente => ({
|
|
IdCliente: cliente.IdCliente,
|
|
NomeCliente: cliente.Nome || 'N/A'
|
|
}));
|
|
resultDiv.textContent = `Clienti trovati:\n${JSON.stringify(clientiList, null, 2)}`;
|
|
} else {
|
|
resultDiv.textContent = `Nessun cliente trovato. Dettagli: ${JSON.stringify(clientiData)}`;
|
|
}
|
|
} catch (error) {
|
|
resultDiv.textContent = `Errore: ${error.message}`;
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|