feat(admin): rebuild admin panel as out-of-band login with backups
- Separate admin login (ADMIN_USERNAME/ADMIN_PASSWORD) with its own JWT, no longer a seeded user account; lockout after 5 failed attempts - Admin panel tabs: Users, Notifications, Backups, Reset - Ntfy settings moved from .env/compose into admin_settings (token encrypted) - Scheduled and on-demand mariadb-dump backups to NFS volume, with restore (entries only or all) and retention pruning - Reset all entries, guarded by an automatic safety backup - Remove user impersonation and the admin link in the user nav - Login page falls back to admin login; nginx sends Cache-Control: no-cache Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c54d2b251f
commit
6272322f31
28 files changed
+1523
-461
No files matched your search
+41
-10
@@ -28,7 +28,7 @@
|
||||
<form id="login-form">
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" id="email" autocomplete="email" required placeholder="[email protected]" />
|
||||
<input type="text" id="email" autocomplete="username" required placeholder="[email protected]" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
@@ -60,19 +60,50 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Signing in…';
|
||||
|
||||
const email = document.getElementById('email').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
try {
|
||||
const email = document.getElementById('email').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
const data = await API.auth.login(email, password);
|
||||
Auth.saveToken(data.access_token);
|
||||
// Raw fetch (not API.auth.login) so a 401 doesn't trigger the global sign-out redirect.
|
||||
const res = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email, password }),
|
||||
});
|
||||
const data = await res.json().catch(() => null);
|
||||
|
||||
// Pre-fetch user info so nav renders immediately
|
||||
const user = await API.users.me();
|
||||
Auth.saveUser(user);
|
||||
if (res.ok) {
|
||||
Auth.saveToken(data.access_token);
|
||||
// Pre-fetch user info so nav renders immediately
|
||||
const user = await API.users.me();
|
||||
Auth.saveUser(user);
|
||||
window.location.href = '/index.html';
|
||||
return;
|
||||
}
|
||||
|
||||
window.location.href = '/index.html';
|
||||
// A rejected normal login might be the out-of-band admin account.
|
||||
if (res.status === 401 || res.status === 422) {
|
||||
const adminRes = await fetch('/api/admin/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: email, password }),
|
||||
});
|
||||
if (adminRes.ok) {
|
||||
const adminData = await adminRes.json();
|
||||
localStorage.setItem('bb_admin_token', adminData.access_token);
|
||||
window.location.href = '/admin.html?v=2';
|
||||
return;
|
||||
}
|
||||
if (adminRes.status === 429) {
|
||||
const adminErr = await adminRes.json().catch(() => null);
|
||||
throw new Error(adminErr?.detail || 'Too many attempts. Try again later.');
|
||||
}
|
||||
throw new Error('Invalid credentials');
|
||||
}
|
||||
|
||||
throw new Error(data?.detail || `HTTP ${res.status}`);
|
||||
} catch (err) {
|
||||
alert.innerHTML = `<div class="alert alert-error">${err.message}</div>`;
|
||||
alert.innerHTML = `<div class="alert alert-error">${escHtml(err.message)}</div>`;
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Sign In';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user