This commit is contained in:
2026-03-23 02:09:14 +01:00
parent 705329d3c2
commit d8d46ed8e9
61 changed files with 6054 additions and 3116 deletions

44
public/js/pages/login.js Normal file
View File

@@ -0,0 +1,44 @@
import { apiPost, authFetchStatus } from '../api.js';
const loadingEl = document.getElementById('page-loading');
const panel = document.getElementById('login-panel');
async function init() {
let st;
try {
st = await authFetchStatus();
} catch {
st = { needsBootstrap: false, loggedIn: false };
}
if (st.needsBootstrap) {
location.href = '/bootstrap.html';
return;
}
if (st.loggedIn) {
location.href = '/start.html';
return;
}
loadingEl.hidden = true;
panel.hidden = false;
document.getElementById('form-login').onsubmit = async (e) => {
e.preventDefault();
const fd = new FormData(e.target);
try {
await apiPost('/auth/login', {
username: fd.get('username'),
password: fd.get('password'),
});
location.href = '/start.html';
} catch (err) {
document.querySelector('.auth-err')?.remove();
const p = document.createElement('p');
p.className = 'error auth-err';
p.textContent = err.message || 'Anmeldung fehlgeschlagen';
document.getElementById('form-login').prepend(p);
}
};
}
init();