- 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]>
115 lines
3.8 KiB
HTML
115 lines
3.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Login — Bourbonacci</title>
|
|
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🥃</text></svg>" />
|
|
<link rel="stylesheet" href="/css/style.css" />
|
|
</head>
|
|
<body>
|
|
|
|
<nav>
|
|
<div class="nav-left">
|
|
<a href="/index.html" class="nav-brand">🥃 Bourbonacci</a>
|
|
<div class="nav-links" id="nav-links"></div>
|
|
</div>
|
|
<div id="nav-user"></div>
|
|
</nav>
|
|
|
|
<div class="auth-wrap">
|
|
<div class="auth-logo">
|
|
<h1>Welcome Back</h1>
|
|
<p>Sign in to manage your infinity bottle</p>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div id="alert"></div>
|
|
<form id="login-form">
|
|
<div class="form-group">
|
|
<label for="email">Email</label>
|
|
<input type="text" id="email" autocomplete="username" required placeholder="[email protected]" />
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input type="password" id="password" autocomplete="current-password" required placeholder="••••••••" />
|
|
</div>
|
|
<button type="submit" class="btn btn-primary" style="width:100%;margin-top:.5rem" id="submit-btn">Sign In</button>
|
|
</form>
|
|
<hr class="divider" />
|
|
<p style="text-align:center;color:var(--cream-dim);font-size:.9rem">
|
|
Don't have an account? <a href="/register.html" style="color:var(--amber)">Register</a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="/js/api.js"></script>
|
|
<script src="/js/auth.js"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
Auth.redirectIfLoggedIn();
|
|
Auth.renderNav();
|
|
|
|
const form = document.getElementById('login-form');
|
|
const alert = document.getElementById('alert');
|
|
const btn = document.getElementById('submit-btn');
|
|
|
|
form.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
alert.innerHTML = '';
|
|
btn.disabled = true;
|
|
btn.textContent = 'Signing in…';
|
|
|
|
const email = document.getElementById('email').value.trim();
|
|
const password = document.getElementById('password').value;
|
|
|
|
try {
|
|
// 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);
|
|
|
|
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;
|
|
}
|
|
|
|
// 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">${escHtml(err.message)}</div>`;
|
|
btn.disabled = false;
|
|
btn.textContent = 'Sign In';
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|