Actualiser admin/login.html
This commit is contained in:
+5
-20
@@ -76,8 +76,7 @@
|
||||
|
||||
async function doLogin() {
|
||||
const pwd = document.getElementById('login-pwd').value;
|
||||
const errEl = document.getElementById('login-err');
|
||||
errEl.style.display = 'none';
|
||||
console.log("Tentative avec le mot de passe :", pwd); // DEBUG
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_URL}?action=login`, {
|
||||
@@ -85,32 +84,18 @@
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password: pwd })
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
console.log("Réponse du serveur :", data); // DEBUG
|
||||
|
||||
if (data.success) {
|
||||
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';
|
||||
} else {
|
||||
errEl.style.display = 'block';
|
||||
document.getElementById('login-err').style.display = 'block';
|
||||
}
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
errEl.style.display = 'block';
|
||||
console.error("Erreur de connexion :", e);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user