feat: User-Management mit Token-basierter Authentifizierung
Backend: - UserRecord Model + Users-Tabelle in DB - AuthService: SHA256-Passwort-Hashing, Token-Verwaltung (ConcurrentDictionary) - AuthMiddleware: Schützt alle /api/-Routes (außer /api/auth/login) - AuthEndpoint: Login, Logout, Me - Default-User admin/admin wird automatisch erstellt Frontend: - Login-Page mit Formular (Enter-Key-Support) - Globaler Fetch-Interceptor: 401 → automatisch Login-Redirect - Auth-Check beim App-Start und bei Hash-Änderungen - Logout-Link im Dashboard-Header - Login-CSS: Zentrierte Login-Box
This commit is contained in:
1 parent
a1c54bf376
commit
9a59ae686d
13 files changed
+446
-3
No files matched your search
@@ -8,6 +8,13 @@ registerPage('dashboard', {
|
||||
navigateTo('settings');
|
||||
});
|
||||
|
||||
// Logout-Link
|
||||
document.getElementById('dashboardLogoutLink').addEventListener('click', async (e) => {
|
||||
e.preventDefault();
|
||||
await apiLogout();
|
||||
navigateTo('login');
|
||||
});
|
||||
|
||||
// Globaler Click-Handler zum Schließen aller Card-Menüs
|
||||
document.addEventListener('click', this._closeCardMenus = () => closeAllCardMenus());
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// ── Login Page ──
|
||||
|
||||
registerPage('login', {
|
||||
init() {
|
||||
const usernameInput = $('#loginUsername');
|
||||
const passwordInput = $('#loginPassword');
|
||||
const loginBtn = $('#loginBtn');
|
||||
const errorDiv = $('#loginError');
|
||||
|
||||
async function doLogin() {
|
||||
errorDiv.hidden = true;
|
||||
loginBtn.disabled = true;
|
||||
loginBtn.textContent = 'Anmelden...';
|
||||
|
||||
try {
|
||||
var username = usernameInput.value.trim();
|
||||
var password = passwordInput.value;
|
||||
|
||||
if (!username || !password) {
|
||||
errorDiv.textContent = 'Benutzername und Passwort eingeben';
|
||||
errorDiv.hidden = false;
|
||||
return;
|
||||
}
|
||||
|
||||
await apiLogin(username, password);
|
||||
navigateTo('dashboard');
|
||||
} catch (err) {
|
||||
errorDiv.textContent = err.message || 'Login fehlgeschlagen';
|
||||
errorDiv.hidden = false;
|
||||
passwordInput.value = '';
|
||||
passwordInput.focus();
|
||||
} finally {
|
||||
loginBtn.disabled = false;
|
||||
loginBtn.textContent = 'Anmelden';
|
||||
}
|
||||
}
|
||||
|
||||
loginBtn.addEventListener('click', doLogin);
|
||||
|
||||
usernameInput.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Enter') passwordInput.focus();
|
||||
});
|
||||
|
||||
passwordInput.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Enter') doLogin();
|
||||
});
|
||||
},
|
||||
destroy() {}
|
||||
});
|
||||
Reference in new issue
Block a user