Files
bourbonacci/frontend/profile.html
derekc f1b82baebd Overhaul nav, fix DB transaction bugs, add admin UI
- Replace nav user area with display name (non-clickable), gear settings
  modal, admin button (admins only), and logout button
- Settings modal handles display name, timezone, and password change
- Add admin.html + admin.js: user table with reset PW, disable/enable,
  login-as (impersonation), and delete; return-to-admin flow in nav
- Add is_admin to UserResponse so frontend can gate the Admin button
- Fix all db.begin() bugs in admin.py and users.py (transaction already
  active from get_current_user query; use commit() directly instead)
- Add email-validator and pin bcrypt==4.0.1 for passlib compatibility
- Add escHtml() to api.js and admin API namespace
- Group nav brand + links in nav-left for left-aligned layout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 21:09:38 -07:00

159 lines
5.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Profile — 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>
<main style="max-width:560px">
<h1 class="page-title">Profile Settings</h1>
<!-- Account info -->
<div class="card">
<div class="card-title">Account Info</div>
<div id="alert-profile"></div>
<form id="form-profile">
<div class="form-group">
<label for="email-display">Email</label>
<input type="text" id="email-display" disabled style="opacity:.5;cursor:not-allowed" />
</div>
<div class="form-group">
<label for="display-name">Display Name</label>
<input type="text" id="display-name" placeholder="How you appear publicly" maxlength="100" />
</div>
<div class="form-group">
<label for="timezone">Time Zone</label>
<select id="timezone"></select>
</div>
<button type="submit" class="btn btn-primary" id="btn-profile">Save Changes</button>
</form>
</div>
<!-- Change password -->
<div class="card">
<div class="card-title">Change Password</div>
<div id="alert-pw"></div>
<form id="form-pw">
<div class="form-group">
<label for="cur-pw">Current Password</label>
<input type="password" id="cur-pw" required autocomplete="current-password" />
</div>
<div class="form-group">
<label for="new-pw">New Password</label>
<input type="password" id="new-pw" required autocomplete="new-password" placeholder="Min 8 characters" />
</div>
<div class="form-group">
<label for="conf-pw">Confirm New Password</label>
<input type="password" id="conf-pw" required autocomplete="new-password" />
</div>
<button type="submit" class="btn btn-primary" id="btn-pw">Update Password</button>
</form>
</div>
</main>
<script src="/js/api.js"></script>
<script src="/js/auth.js"></script>
<script>
const TIMEZONES = [
'UTC',
'America/New_York','America/Chicago','America/Denver','America/Los_Angeles',
'America/Anchorage','Pacific/Honolulu',
'America/Toronto','America/Vancouver','America/Winnipeg',
'Europe/London','Europe/Paris','Europe/Berlin','Europe/Moscow',
'Asia/Tokyo','Asia/Shanghai','Asia/Kolkata','Asia/Dubai',
'Australia/Sydney','Australia/Perth',
'Pacific/Auckland',
];
document.addEventListener('DOMContentLoaded', async () => {
if (!Auth.requireAuth()) return;
await Auth.renderNav();
// Populate timezone select
const tzSel = document.getElementById('timezone');
TIMEZONES.forEach(tz => {
const opt = document.createElement('option');
opt.value = tz;
opt.textContent = tz.replace('_', ' ');
tzSel.appendChild(opt);
});
try {
const user = await API.users.me();
Auth.saveUser(user);
document.getElementById('email-display').value = user.email;
document.getElementById('display-name').value = user.display_name || '';
tzSel.value = user.timezone || 'UTC';
} catch (err) {
document.getElementById('alert-profile').innerHTML = `<div class="alert alert-error">Failed to load profile: ${err.message}</div>`;
}
});
document.getElementById('form-profile').addEventListener('submit', async (e) => {
e.preventDefault();
const alert = document.getElementById('alert-profile');
const btn = document.getElementById('btn-profile');
alert.innerHTML = '';
btn.disabled = true;
try {
const user = await API.users.update({
display_name: document.getElementById('display-name').value.trim() || null,
timezone: document.getElementById('timezone').value,
});
Auth.saveUser(user);
alert.innerHTML = `<div class="alert alert-success">Profile updated.</div>`;
} catch (err) {
alert.innerHTML = `<div class="alert alert-error">${err.message}</div>`;
} finally {
btn.disabled = false;
}
});
document.getElementById('form-pw').addEventListener('submit', async (e) => {
e.preventDefault();
const alert = document.getElementById('alert-pw');
const btn = document.getElementById('btn-pw');
const newPw = document.getElementById('new-pw').value;
const confPw = document.getElementById('conf-pw').value;
alert.innerHTML = '';
if (newPw !== confPw) {
alert.innerHTML = `<div class="alert alert-error">New passwords do not match.</div>`;
return;
}
if (newPw.length < 8) {
alert.innerHTML = `<div class="alert alert-error">Password must be at least 8 characters.</div>`;
return;
}
btn.disabled = true;
try {
await API.users.changePassword({
current_password: document.getElementById('cur-pw').value,
new_password: newPw,
});
alert.innerHTML = `<div class="alert alert-success">Password updated.</div>`;
e.target.reset();
} catch (err) {
alert.innerHTML = `<div class="alert alert-error">${err.message}</div>`;
} finally {
btn.disabled = false;
}
});
</script>
</body>
</html>