BillTracker/public/login.html

175 lines
5.7 KiB
HTML
Raw Normal View History

2026-05-03 19:51:57 -05:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bill Tracker — Sign In</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0d1526;
--surface: #162236;
--surface-2: #1c2d47;
--border: rgba(255,255,255,0.07);
--border-strong: rgba(255,255,255,0.14);
--text: #e2e8f0;
--text-muted: #8faab8;
--text-faint: #506070;
--primary: #6366f1;
--primary-hover: #4f46e5;
--primary-light: rgba(99,102,241,0.18);
--danger: #f43f5e;
--danger-light: rgba(244,63,94,0.15);
--radius: 6px;
--font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
body {
font-family: var(--font);
font-size: 14px;
background: var(--bg);
color: var(--text);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-image:
radial-gradient(ellipse at 20% 50%, rgba(99,102,241,0.06) 0%, transparent 60%),
radial-gradient(ellipse at 80% 20%, rgba(34,211,165,0.04) 0%, transparent 50%);
}
.card {
background: var(--surface);
border: 1px solid var(--border-strong);
border-radius: 12px;
padding: 36px 32px;
width: 100%;
max-width: 360px;
box-shadow: 0 24px 60px rgba(0,0,0,0.5), 0 0 0 1px var(--border);
}
.logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.logo-icon {
width: 36px; height: 36px;
background: var(--primary);
border-radius: var(--radius);
display: flex; align-items: center; justify-content: center;
font-weight: 800; font-size: 17px; color: white;
box-shadow: 0 0 16px rgba(99,102,241,0.4);
}
.logo-text { font-size: 18px; font-weight: 700; color: var(--text); }
h2 { font-size: 15px; font-weight: 500; margin-bottom: 22px; color: var(--text-muted); }
.form-group { margin-bottom: 14px; }
label {
display: block;
font-size: 11px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: .05em;
color: var(--text-muted);
margin-bottom: 6px;
}
input {
width: 100%;
padding: 9px 11px;
border: 1px solid var(--border-strong);
border-radius: var(--radius);
font-size: 14px;
font-family: var(--font);
color: var(--text);
background: var(--surface-2);
transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--text-faint); }
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.2); }
.btn {
width: 100%;
padding: 10px;
border: none;
border-radius: var(--radius);
font-size: 14px;
font-family: var(--font);
font-weight: 600;
cursor: pointer;
background: var(--primary);
color: white;
margin-top: 6px;
transition: background .15s, box-shadow .15s;
}
.btn:hover:not(:disabled) { background: var(--primary-hover); box-shadow: 0 0 0 3px rgba(99,102,241,0.25); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.error {
background: var(--danger-light);
color: var(--danger);
border: 1px solid rgba(244,63,94,0.3);
border-radius: var(--radius);
padding: 9px 12px;
font-size: 13px;
margin-bottom: 14px;
display: none;
}
.error.show { display: block; }
</style>
</head>
<body>
<div class="card">
<div class="logo">
<div class="logo-icon">$</div>
<span class="logo-text">BillTracker</span>
</div>
<h2>Sign in to your account</h2>
<div class="error" id="error-msg"></div>
<form id="login-form">
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" autocomplete="username" autocapitalize="none" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" autocomplete="current-password" required>
</div>
<button class="btn" type="submit" id="submit-btn">Sign In</button>
</form>
</div>
<script>
// If single-user mode is active, no login needed — go straight to the app
fetch('/api/auth/mode').then(r => r.json()).then(d => {
if (d.auth_mode === 'single') { location.href = '/'; return; }
});
// Redirect if already logged in
fetch('/api/auth/me').then(r => {
if (r.ok) return r.json().then(d => {
location.href = d.user.role === 'admin' ? '/admin.html' : '/';
});
});
document.getElementById('login-form').onsubmit = async (e) => {
e.preventDefault();
const btn = document.getElementById('submit-btn');
const err = document.getElementById('error-msg');
btn.disabled = true;
btn.textContent = 'Signing in…';
err.classList.remove('show');
try {
const res = await fetch('/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
username: document.getElementById('username').value,
password: document.getElementById('password').value,
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || 'Login failed');
location.href = data.user.role === 'admin' ? '/admin.html' : '/';
} catch (ex) {
err.textContent = ex.message;
err.classList.add('show');
btn.disabled = false;
btn.textContent = 'Sign In';
}
};
</script>
</body>
</html>