Actualiser admin/login.html
This commit is contained in:
+110
-53
@@ -2,10 +2,63 @@
|
|||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Connexion | Administration</title>
|
<title>Connexion | Administration</title>
|
||||||
<link rel="stylesheet" href="../css/admin.css">
|
<link rel="stylesheet" href="../css/admin.css">
|
||||||
<style>
|
<style>
|
||||||
body { background-color: #0a0a0a; display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
|
/* Styles spécifiques à la page de login pour centrer le tout */
|
||||||
|
body {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 100vh;
|
||||||
|
background: var(--background);
|
||||||
|
}
|
||||||
|
.login-wrap {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 400px;
|
||||||
|
padding: 2.5rem;
|
||||||
|
background: var(--surface-card);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 16px;
|
||||||
|
text-align: center;
|
||||||
|
box-shadow: var(--shadow-overlay);
|
||||||
|
}
|
||||||
|
.login-wrap h2 {
|
||||||
|
font-size: 1.8rem;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.login-wrap h2 span { color: var(--gold); }
|
||||||
|
.login-wrap input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.9rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
background: var(--background);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
color: var(--text);
|
||||||
|
text-align: center;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
.login-wrap input:focus {
|
||||||
|
border-color: var(--gold);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.btn-gold {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.9rem;
|
||||||
|
background: var(--gold);
|
||||||
|
color: var(--background);
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
.btn-gold:hover {
|
||||||
|
box-shadow: 0 0 15px var(--gold-glow);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -15,75 +68,79 @@
|
|||||||
|
|
||||||
<div id="login-form-block">
|
<div id="login-form-block">
|
||||||
<input type="password" id="login-pwd" placeholder="Mot de passe" onkeydown="if(event.key==='Enter') doLogin()">
|
<input type="password" id="login-pwd" placeholder="Mot de passe" onkeydown="if(event.key==='Enter') doLogin()">
|
||||||
<button class="btn btn-gold" onclick="doLogin()">Se connecter</button>
|
<button class="btn-gold" onclick="doLogin()">Se connecter</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="blank-setup-block" style="display:none;">
|
<div id="blank-setup-block" style="display:none;">
|
||||||
<p style="color: #aaaab8; margin-bottom: 1.5rem; font-size: 0.9rem;">
|
<p style="color: var(--muted); margin-bottom: 1.5rem; font-size: 0.9rem;">
|
||||||
Système initialisé. Cliquez pour définir votre accès.
|
Système initialisé. Cliquez pour définir votre mot de passe administrateur.
|
||||||
</p>
|
</p>
|
||||||
<button class="btn btn-gold" onclick="doLoginBlank()">Initialiser le compte</button>
|
<button class="btn-gold" onclick="doLoginBlank()">Initialiser le compte</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const API_URL = '../api.php';
|
const API_URL = '../api.php';
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
const formBlock = document.getElementById('login-form-block');
|
const formBlock = document.getElementById('login-form-block');
|
||||||
const blankBlock = document.getElementById('blank-setup-block');
|
const blankBlock = document.getElementById('blank-setup-block');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}?action=check_security_status`);
|
const res = await fetch(`${API_URL}?action=check_security_status`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data.is_blank === true) {
|
if (data.is_blank) {
|
||||||
formBlock.style.display = 'none';
|
formBlock.style.display = 'none';
|
||||||
blankBlock.style.display = 'block';
|
blankBlock.style.display = 'block';
|
||||||
} else {
|
|
||||||
formBlock.style.display = 'block';
|
|
||||||
blankBlock.style.display = 'none';
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
console.error("Erreur API :", e);
|
|
||||||
alert("Erreur de connexion au serveur.");
|
|
||||||
}
|
}
|
||||||
});
|
} catch (e) {
|
||||||
|
console.error("Erreur d'initialisation", e);
|
||||||
async function doLoginBlank() { await performLogin(""); }
|
|
||||||
async function doLogin() {
|
|
||||||
const pwd = document.getElementById('login-pwd').value;
|
|
||||||
await performLogin(pwd);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
async function performLogin(pwd) {
|
async function doLogin() {
|
||||||
try {
|
const pwd = document.getElementById('login-pwd').value;
|
||||||
const res = await fetch(`${API_URL}?action=login`, {
|
await performLogin(pwd);
|
||||||
method: 'POST',
|
}
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ password: pwd })
|
async function doLoginBlank() {
|
||||||
});
|
await performLogin('');
|
||||||
const data = await res.json();
|
}
|
||||||
if (data.success) {
|
|
||||||
localStorage.setItem('token', data.token);
|
async function performLogin(pwd) {
|
||||||
if (data.blank === true) {
|
try {
|
||||||
const newPwd = prompt("Définissez votre mot de passe (min 4 caractères) :");
|
const res = await fetch(`${API_URL}?action=login`, {
|
||||||
if (newPwd && newPwd.length >= 4) {
|
method: 'POST',
|
||||||
await fetch(`${API_URL}?action=setup_admin`, {
|
headers: { 'Content-Type': 'application/json' },
|
||||||
method: 'POST',
|
body: JSON.stringify({ password: pwd })
|
||||||
headers: { 'Content-Type': 'application/json', 'Authorization': data.token },
|
});
|
||||||
body: JSON.stringify({ password: newPwd })
|
const data = await res.json();
|
||||||
});
|
|
||||||
}
|
if (data.success) {
|
||||||
|
localStorage.setItem('token', data.token);
|
||||||
|
if (data.blank === true) {
|
||||||
|
const newPwd = prompt("Définissez votre mot de passe (min 4 caractères) :");
|
||||||
|
if (newPwd && newPwd.length >= 4) {
|
||||||
|
await fetch(`${API_URL}?action=setup_admin`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json', 'Authorization': data.token },
|
||||||
|
body: JSON.stringify({ password: newPwd })
|
||||||
|
});
|
||||||
|
alert("Mot de passe configuré ! Redirection...");
|
||||||
|
} else {
|
||||||
|
alert("Initialisation annulée.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
window.location.href = 'dashboard.html';
|
|
||||||
} else {
|
|
||||||
alert("Erreur : " + (data.error || "Mot de passe incorrect"));
|
|
||||||
}
|
}
|
||||||
} catch(e) {
|
window.location.href = 'dashboard.html';
|
||||||
alert("Erreur technique : " + e.message);
|
} else {
|
||||||
|
alert("Erreur : " + (data.error || "Mot de passe incorrect"));
|
||||||
}
|
}
|
||||||
|
} catch(e) {
|
||||||
|
alert("Erreur technique : " + e.message);
|
||||||
}
|
}
|
||||||
</script>
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user