From 7356db2306b097e76981674a3b69e4111fc96509 Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 18 Jun 2026 12:14:27 +0200 Subject: [PATCH] Actualiser admin/login.html --- admin/login.html | 49 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/admin/login.html b/admin/login.html index d3c0e5b..f2b54f2 100644 --- a/admin/login.html +++ b/admin/login.html @@ -75,44 +75,29 @@ } async function doLogin() { - const pwd = document.getElementById('login-pwd').value; - const errEl = document.getElementById('login-err'); - errEl.style.display = 'none'; + const pwd = document.getElementById('login-pwd').value; + console.log("Tentative avec le mot de passe :", pwd); // DEBUG try { - const res = await fetch(`${API_URL}?action=login`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ password: pwd }) - }); - const data = await res.json(); + const res = await fetch(`${API_URL}?action=login`, { + method: 'POST', + 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() }) - }); - } + if (data.success) { + localStorage.setItem('token', data.token); + window.location.href = 'dashboard.html'; + } else { + document.getElementById('login-err').style.display = 'block'; } - window.location.href = 'dashboard.html'; - } else { - errEl.style.display = 'block'; - } } catch(e) { - console.error(e); - errEl.style.display = 'block'; + console.error("Erreur de connexion :", e); } - } +} \ No newline at end of file