Move to FastAPI with accounts, SQLite books, export and tax returns
Storage and export - Keep books and transactions in SQLite (data/cashbook.db) instead of .ods files; existing .ods books are migrated once at startup - Export a book as the cashbook spreadsheet (.xlsx/.ods, built from the template via LibreOffice) or as CSV - GST rounded per transaction to match the spreadsheet Tax - GST return page with IRD GST101A boxes 5-15 per six-monthly, two-monthly or monthly period, due dates, and a Zero-rated GST type - Income tax page with IR10 (financial statements summary) and IR4 (company return) boxes, from the cashbook plus year-end amounts typed in and saved per book FastAPI and accounts (following led-editor) - Replace the stdlib server with a FastAPI app (src/cashbook_app) run by uvicorn; dependencies in Pipfile - Cookie sessions with bcrypt passwords, first-run admin setup or BOOTSTRAP_ADMIN_*, invites (link or email), sign-in throttling, password change that signs out other sessions - Users page for administrators: rename, reset password, promote or demote, delete, list and revoke invites; last admin is protected - Replaces the shared CASHBOOK_PASSWORD basic auth; AUTH_* settings in .env (see .env.example) - Docker image uses a venv with system site packages for python3-uno - pytest suite for auth, user management, imports, GST and tax figures Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
17b48f25e8
commit
4b3e5f0932
47 files changed
+4189
-862
No files matched your search
@@ -0,0 +1,65 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Sign in · Cashbook</title>
|
||||
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='7' fill='%230b6bcb'/%3E%3Ctext x='16' y='23' font-size='19' font-family='sans-serif' font-weight='700' text-anchor='middle' fill='white'%3E$%3C/text%3E%3C/svg%3E">
|
||||
<link rel="stylesheet" href="/static/auth.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="center">
|
||||
<main class="card">
|
||||
<h1>Cashbook</h1>
|
||||
<div class="muted" style="margin-bottom:12px">Sign in to continue.</div>
|
||||
<div id="setup" class="notice" hidden>
|
||||
There are no accounts yet. <a href="/register">Create the administrator account</a> to get started.
|
||||
</div>
|
||||
<form id="form">
|
||||
<label for="username">Username</label>
|
||||
<input id="username" type="text" autocomplete="username" autocapitalize="none" required autofocus>
|
||||
<label for="password">Password</label>
|
||||
<input id="password" type="password" autocomplete="current-password" required>
|
||||
<div id="err" class="error" role="alert"></div>
|
||||
<button type="submit" class="primary" id="submit">Sign in</button>
|
||||
</form>
|
||||
<div class="links muted" id="registerLinks" hidden>Have an invite? Open the link you were sent.</div>
|
||||
</main>
|
||||
</div>
|
||||
<script>
|
||||
const next = new URLSearchParams(location.search).get("next");
|
||||
const target = next && next.startsWith("/") && !next.startsWith("//") ? next : "/";
|
||||
const errorText = j => Array.isArray(j.detail) ? j.detail.map(e => e.msg).join("; ") : (j.detail || "Sign-in failed");
|
||||
|
||||
(async () => {
|
||||
const s = await fetch("/api/auth/status").then(r => r.json()).catch(() => null);
|
||||
if (!s) return;
|
||||
if (!s.auth_enabled) { location.href = "/"; return; }
|
||||
if (s.setup_required) { document.getElementById("setup").hidden = false; document.getElementById("form").hidden = true; }
|
||||
else document.getElementById("registerLinks").hidden = !s.register_open;
|
||||
// already signed in?
|
||||
const me = await fetch("/api/auth/me");
|
||||
if (me.ok) location.href = target;
|
||||
})();
|
||||
|
||||
document.getElementById("form").addEventListener("submit", async e => {
|
||||
e.preventDefault();
|
||||
const err = document.getElementById("err"), btn = document.getElementById("submit");
|
||||
err.textContent = ""; btn.disabled = true;
|
||||
try {
|
||||
const res = await fetch("/api/auth/login", {
|
||||
method: "POST", headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username: document.getElementById("username").value.trim(),
|
||||
password: document.getElementById("password").value }),
|
||||
});
|
||||
if (!res.ok) { err.textContent = errorText(await res.json().catch(() => ({}))); return; }
|
||||
location.href = target;
|
||||
} catch (ex) {
|
||||
err.textContent = ex.message;
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user