auth: add first-run setup page
This commit is contained in:
parent
3b823ab18e
commit
0709e07a05
47
containers/clearview/site/setup.html
Normal file
47
containers/clearview/site/setup.html
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Clearview — First-time setup</title>
|
||||||
|
<link rel="stylesheet" href="/styles.css" />
|
||||||
|
</head>
|
||||||
|
<body class="auth-page">
|
||||||
|
<main class="auth-card">
|
||||||
|
<h1>Welcome to Clearview</h1>
|
||||||
|
<p class="auth-sub">Create the first administrator account.</p>
|
||||||
|
<form id="setupForm">
|
||||||
|
<label>Username<input name="username" autocomplete="username" required autofocus /></label>
|
||||||
|
<label>Password (≥12 chars, letter + digit)<input name="password" type="password" autocomplete="new-password" required minlength="12" /></label>
|
||||||
|
<button type="submit">Create administrator</button>
|
||||||
|
<p id="setupError" class="auth-error" hidden></p>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
<script src="/auth.js"></script>
|
||||||
|
<script>
|
||||||
|
(async function () {
|
||||||
|
const probe = await ClearviewAuth.getJson('/api/auth/setup-required');
|
||||||
|
if (!probe.ok || !probe.data || !probe.data.setup_required) {
|
||||||
|
window.location.replace('/login.html');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const form = document.getElementById('setupForm');
|
||||||
|
const err = document.getElementById('setupError');
|
||||||
|
form.addEventListener('submit', async (ev) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
err.hidden = true;
|
||||||
|
const fd = new FormData(form);
|
||||||
|
const res = await ClearviewAuth.postJson('/api/auth/setup', {
|
||||||
|
username: fd.get('username'),
|
||||||
|
password: fd.get('password'),
|
||||||
|
});
|
||||||
|
if (res.ok) {
|
||||||
|
window.location.replace('/');
|
||||||
|
} else {
|
||||||
|
err.textContent = (res.data && res.data.detail) || 'Setup failed';
|
||||||
|
err.hidden = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user