97 lines
3.1 KiB
HTML
97 lines
3.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link rel="stylesheet" href="../css/admin.css">
|
|
<title>Login - Backoffice</title>
|
|
</head>
|
|
<body>
|
|
<div id="page-login" class="page active">
|
|
<div class="login-wrap">
|
|
<h2>Backoffice</h2>
|
|
|
|
<div id="login-form-block">
|
|
<input type="password" id="login-pwd" placeholder="Mot de passe" onkeydown="if(event.key==='Enter') doLogin()" />
|
|
<p class="login-err" id="login-err">Mot de passe incorrect.</p>
|
|
<button class="btn btn-gold" onclick="doLogin()">Accéder</button>
|
|
</div>
|
|
|
|
<div id="blank-setup-block" style="display:none; text-align:center;">
|
|
<p style="color:var(--muted, #aaa); font-size:0.85rem; margin-bottom:1.5rem; line-height:1.6;">
|
|
Aucun mot de passe configuré sur le serveur.<br>Connectez-vous directement pour en définir un.
|
|
</p>
|
|
<button class="btn btn-gold" onclick="doLoginBlank()" style="width:100%;">Se connecter sans mot de passe</button>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const API_URL = '../api.php';
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
const formBlock = document.getElementById('login-form-block');
|
|
const blankBlock = document.getElementById('blank-setup-block');
|
|
|
|
try {
|
|
const res = await fetch(`${API_URL}?action=check_security_status`);
|
|
const data = await res.json();
|
|
console.log("DEBUG - Statut sécurité :", data); // OUVREZ LA CONSOLE F12 POUR VOIR CE RÉSULTAT
|
|
|
|
if (data.is_blank) {
|
|
formBlock.style.display = 'none';
|
|
blankBlock.style.display = 'block';
|
|
} else {
|
|
formBlock.style.display = 'block';
|
|
blankBlock.style.display = 'none';
|
|
}
|
|
} catch(e) {
|
|
console.error("Erreur API :", e);
|
|
}
|
|
});
|
|
|
|
async function doLoginBlank() {
|
|
try {
|
|
const res = await fetch(`${API_URL}?action=login`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ password: '' })
|
|
});
|
|
const data = await res.json();
|
|
if (data.success) {
|
|
localStorage.setItem('token', data.token);
|
|
window.location.href = 'dashboard.html';
|
|
}
|
|
} catch(e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
async function doLogin() {
|
|
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();
|
|
console.log("Réponse du serveur :", data); // DEBUG
|
|
|
|
if (data.success) {
|
|
localStorage.setItem('token', data.token);
|
|
window.location.href = 'dashboard.html';
|
|
} else {
|
|
document.getElementById('login-err').style.display = 'block';
|
|
}
|
|
} catch(e) {
|
|
console.error("Erreur de connexion :", e);
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |