Ausgaben-WebApp: Puppet-Modul (Flask + Gunicorn + SQLite, Docker Compose)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"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();
|
||||
try {
|
||||
await fetchJSON("/api/passwort", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
altes_passwort: document.getElementById("altes-passwort").value,
|
||||
neues_passwort: document.getElementById("neues-passwort").value,
|
||||
}),
|
||||
});
|
||||
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");
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user