- Profil: zweites Passwortfeld 'Neues Passwort wiederholen' - Clientseitige Validierung: beide Felder müssen übereinstimmen Co-Authored-By: Claude Code <noreply@anthropic.com>
49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
"use strict";
|
|
|
|
const passwortForm = document.getElementById("passwort-form");
|
|
const passwortMsg = document.getElementById("passwort-message");
|
|
|
|
async function fetchJSON(url, options = {}) {
|
|
const res = await fetch(url, options);
|
|
if (res.status === 401) {
|
|
window.location.href = "/login";
|
|
throw new Error("Nicht angemeldet");
|
|
}
|
|
const data = await res.json().catch(() => ({}));
|
|
if (!res.ok) throw new Error(data.error || "Unerwarteter Fehler");
|
|
return data;
|
|
}
|
|
|
|
passwortForm.addEventListener("submit", async (e) => {
|
|
e.preventDefault();
|
|
const neues = document.getElementById("neues-passwort").value;
|
|
const wiederholung = document.getElementById("neues-passwort-wdh").value;
|
|
|
|
// Clientseitige Prüfung: beide Felder müssen übereinstimmen
|
|
if (neues !== wiederholung) {
|
|
passwortMsg.textContent = "Die beiden neuen Passwörter stimmen nicht überein.";
|
|
passwortMsg.className = "alert alert-error";
|
|
passwortMsg.classList.remove("hidden");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await fetchJSON("/api/passwort", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
altes_passwort: document.getElementById("altes-passwort").value,
|
|
neues_passwort: neues,
|
|
}),
|
|
});
|
|
passwortForm.reset();
|
|
passwortMsg.textContent = "Passwort erfolgreich geändert ✓";
|
|
passwortMsg.className = "alert alert-ok";
|
|
passwortMsg.classList.remove("hidden");
|
|
setTimeout(() => passwortMsg.classList.add("hidden"), 4000);
|
|
} catch (err) {
|
|
passwortMsg.textContent = err.message;
|
|
passwortMsg.className = "alert alert-error";
|
|
passwortMsg.classList.remove("hidden");
|
|
}
|
|
}); |