Actualiser admin/login.html

This commit is contained in:
2026-06-18 12:14:27 +02:00
parent 36812a464d
commit 7356db2306
+17 -32
View File
@@ -75,44 +75,29 @@
} }
async function doLogin() { async function doLogin() {
const pwd = document.getElementById('login-pwd').value; const pwd = document.getElementById('login-pwd').value;
const errEl = document.getElementById('login-err'); console.log("Tentative avec le mot de passe :", pwd); // DEBUG
errEl.style.display = 'none';
try { try {
const res = await fetch(`${API_URL}?action=login`, { const res = await fetch(`${API_URL}?action=login`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: pwd }) body: JSON.stringify({ password: pwd })
}); });
const data = await res.json();
const data = await res.json();
console.log("Réponse du serveur :", data); // DEBUG
if (data.success) { if (data.success) {
localStorage.setItem('token', data.token); localStorage.setItem('token', data.token);
window.location.href = 'dashboard.html';
// Première connexion : inviter à définir un mot de passe } else {
if (data.blank) { document.getElementById('login-err').style.display = 'block';
const newPwd = prompt("Première connexion ! Définissez votre mot de passe administrateur :");
if (newPwd && newPwd.trim().length >= 4) {
await fetch(`${API_URL}?action=setup_admin`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': data.token
},
body: JSON.stringify({ password: newPwd.trim() })
});
}
} }
window.location.href = 'dashboard.html';
} else {
errEl.style.display = 'block';
}
} catch(e) { } catch(e) {
console.error(e); console.error("Erreur de connexion :", e);
errEl.style.display = 'block';
} }
} }
</script> </script>
</body> </body>
</html> </html>