Actualiser admin/login.html

This commit is contained in:
2026-06-18 12:14:27 +02:00
parent 36812a464d
commit 7356db2306
+6 -21
View File
@@ -76,8 +76,7 @@
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`, {
@@ -85,34 +84,20 @@
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);
// Première connexion : inviter à définir un mot de passe
if (data.blank) {
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'; window.location.href = 'dashboard.html';
} else { } else {
errEl.style.display = 'block'; document.getElementById('login-err').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>