public/js/admin.js aktualisiert
This commit is contained in:
parent
b1f96183f3
commit
41812c93f5
|
@ -36,11 +36,21 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
timerDisplay.style.display = 'none';
|
timerDisplay.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Holen Sie sich das Passwort von der API
|
// Holen Sie sich das Passwort und die letzten 3 Passwörter von der API
|
||||||
fetch('/api/admin-password')
|
fetch('/api/admin-password')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const correctPassword = data.password;
|
const correctPassword = data.password;
|
||||||
|
const passwordChangeRequired = data.passwordChangeRequired; // Passwortänderung erforderlich
|
||||||
|
const lastThreePasswords = data.lastThreePasswords || []; // Letzte 3 Passwörter
|
||||||
|
|
||||||
|
// Wenn Passwortänderung erforderlich ist, blockiere den Login
|
||||||
|
if (passwordChangeRequired) {
|
||||||
|
errorMessage.textContent = "⚠️ Das Passwort muss geändert werden, bevor ein Login möglich ist.";
|
||||||
|
errorMessage.style.display = 'block';
|
||||||
|
loginForm.style.display = 'none'; // Verhindere den Login
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById("form").onsubmit = function(event) {
|
document.getElementById("form").onsubmit = function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -75,6 +85,48 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
errorMessage.style.display = 'block';
|
errorMessage.style.display = 'block';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Passwortänderungsfunktion mit Überprüfung der letzten 3 Passwörter
|
||||||
|
window.changePassword = function(newPassword) {
|
||||||
|
fetch('/api/change-password', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ newPassword }),
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const lastThreePasswords = data.lastThreePasswords || [];
|
||||||
|
|
||||||
|
// Prüfen, ob das neue Passwort in den letzten 3 Passwörtern enthalten ist
|
||||||
|
if (lastThreePasswords.includes(newPassword)) {
|
||||||
|
alert("⚠️ Das neue Passwort darf nicht eines der letzten 3 verwendeten Passwörter sein.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Passwort ändern und aktualisieren
|
||||||
|
fetch('/api/update-password', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ newPassword }),
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
alert("✅ Passwort erfolgreich geändert.");
|
||||||
|
localStorage.setItem("adminPassword", newPassword); // Neues Passwort speichern
|
||||||
|
location.reload(); // Seite neu laden, um das neue Passwort zu aktivieren
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Fehler beim Ändern des Passworts:', error);
|
||||||
|
alert("❌ Fehler beim Ändern des Passworts.");
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Fehler beim Überprüfen des Passworts:', error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
window.logout = function() {
|
window.logout = function() {
|
||||||
localStorage.removeItem("adminPassword");
|
localStorage.removeItem("adminPassword");
|
||||||
adminArea.style.display = 'none';
|
adminArea.style.display = 'none';
|
||||||
|
@ -108,6 +160,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
document.getElementById('dashboard-link').onclick = function() {
|
document.getElementById('dashboard-link').onclick = function() {
|
||||||
document.getElementById('dashboard').style.display = 'block';
|
document.getElementById('dashboard').style.display = 'block';
|
||||||
document.getElementById('logs').style.display = 'none';
|
document.getElementById('logs').style.display = 'none';
|
||||||
|
|
Loading…
Reference in New Issue