Actualiser admin/login.html
This commit is contained in:
+16
-31
@@ -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();
|
|
||||||
|
|
||||||
if (data.success) {
|
const data = await res.json();
|
||||||
localStorage.setItem('token', data.token);
|
console.log("Réponse du serveur :", data); // DEBUG
|
||||||
|
|
||||||
// Première connexion : inviter à définir un mot de passe
|
if (data.success) {
|
||||||
if (data.blank) {
|
localStorage.setItem('token', data.token);
|
||||||
const newPwd = prompt("Première connexion ! Définissez votre mot de passe administrateur :");
|
window.location.href = 'dashboard.html';
|
||||||
if (newPwd && newPwd.trim().length >= 4) {
|
} else {
|
||||||
await fetch(`${API_URL}?action=setup_admin`, {
|
document.getElementById('login-err').style.display = 'block';
|
||||||
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>
|
||||||
Reference in New Issue
Block a user