all
This commit is contained in:
+108
-9
@@ -1,16 +1,115 @@
|
||||
<!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</title></head>
|
||||
<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>
|
||||
<input type="password" id="login-pwd" placeholder="Mot de passe" />
|
||||
<p class="login-err" id="login-err">Mot de passe incorrect.</p>
|
||||
<button class="btn btn-gold" onclick="doLogin()">Accéder</button>
|
||||
|
||||
<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 src="../js/admin.js"></script>
|
||||
</body></html>
|
||||
|
||||
<script>
|
||||
const API_URL = '../api.php';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
// Si déjà connecté, rediriger vers le dashboard
|
||||
if (localStorage.getItem('token')) {
|
||||
window.location.href = 'dashboard.html';
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
if (data.is_blank) {
|
||||
formBlock.style.display = 'none';
|
||||
blankBlock.style.display = 'block';
|
||||
}
|
||||
} catch(e) {
|
||||
console.warn("API indisponible — mode secours activé.");
|
||||
formBlock.style.display = 'none';
|
||||
blankBlock.style.display = 'block';
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
const errEl = document.getElementById('login-err');
|
||||
errEl.style.display = 'none';
|
||||
|
||||
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();
|
||||
|
||||
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';
|
||||
}
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
errEl.style.display = 'block';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user