This commit is contained in:
2026-09-07 11:39:39 +02:00
parent 59722ee255
commit d0e022484e
10 changed files with 440 additions and 30 deletions

41
static/login.js Normal file
View File

@@ -0,0 +1,41 @@
const form = document.getElementById("login-form");
const passwordInput = document.getElementById("password");
const errorEl = document.getElementById("login-error");
// If already logged in, skip straight to the app.
fetch("/api/me").then((res) => {
if (res.ok) window.location.href = "/";
});
form.addEventListener("submit", async (e) => {
e.preventDefault();
errorEl.textContent = "";
const submitBtn = form.querySelector(".login-submit");
submitBtn.disabled = true;
try {
const res = await fetch("/api/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ password: passwordInput.value }),
});
if (res.ok) {
window.location.href = "/";
return;
}
if (res.status === 429) {
errorEl.textContent = "Zu viele Fehlversuche. Bitte kurz warten.";
} else {
errorEl.textContent = "Falsches Passwort.";
}
passwordInput.value = "";
passwordInput.focus();
} catch (err) {
errorEl.textContent = "Verbindung fehlgeschlagen.";
} finally {
submitBtn.disabled = false;
}
});