firebreak/web/app/templates/settings.html
ZTatman 8e56a5bb1c feat(web): setup wizard, settings page, and Myst → Firebreak rename
Replace manual .env configuration with a browser-based setup wizard.
New users deploy with `docker compose up` and configure Forgejo OAuth
credentials through /setup on first visit. Existing users can
reconfigure via the same page (auth-gated post-setup).

Key changes:

Rename (Myst → Firebreak):
- Config fields, env vars, session cookie, templates, docker-compose,
  README all renamed from Myst to Firebreak

Setup wizard (/setup):
- New AppSettings single-row DB table stores Forgejo config
- Auto-generates Fernet encryption key on first setup
- SetupRequiredMiddleware redirects all routes to /setup pre-config
- Reconfigure mode pre-fills existing values, requires auth
- Landing page links to /setup for recovery if OAuth breaks

Settings page (/settings):
- PAT registration moved out of dashboard into dedicated page
- Token card with registration date, delete, and update actions
- Dashboard shows CTA linking to settings when no PAT registered

Auth updates:
- Routes use AppSettings from DB instead of env-based Settings
- OAuth callback redirects new users to /settings for PAT setup
- Forgejo API errors no longer leak upstream response bodies
- Decrypt failures return actionable 503 instead of unhandled 500

Code quality:
- Extracted templating.py to eliminate circular import hacks
- AppSettings.get_fernet() caches Fernet cipher instance
- User.has_pat property replaces scattered None checks
- lookup_session promoted to public API
- Dead code removed, return type annotations added
- PAT input fields use type="password"
- CSRF gap documented in agents.md for future addressing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-03 11:15:44 -04:00

134 lines
5.2 KiB
HTML

{% extends "base.html" %}
{% block title %}Settings — Firebreak{% endblock %}
{% block content %}
<div class="flex flex-col gap-6">
<section class="pb-6 border-b border-border">
<h1 class="text-2xl font-semibold">Settings</h1>
<p class="mt-2 text-sm text-muted-foreground">Manage your Firebreak configuration.</p>
</section>
{% if pat_deleted %}
<div class="rounded-md border-l-4 border-warning bg-warning-muted px-4 py-3 text-sm font-semibold text-warning-foreground"
role="status">Access token removed.</div>
{% endif %}
<div id="forgejo-access-token">
<h2 class="text-base font-semibold">Forgejo access token</h2>
<p class="mt-2 text-sm text-muted-foreground">
A <code class="rounded-sm bg-secondary px-1.5 py-0.5 text-foreground">read:repository</code>-scoped
Personal Access Token is required for share link viewing.
</p>
{% if pat_registered %}
<div class="mt-4 card">
<div class="flex items-center justify-between px-4 py-3.5">
<div class="flex items-center gap-3">
<div class="flex size-8 items-center justify-center rounded-md bg-success-muted text-success-foreground">
<svg xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round">
<path d="M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4" />
</svg>
</div>
<div>
<p class="text-sm font-medium text-foreground">Access token</p>
<p class="mt-0.5 text-xs text-muted-foreground">
{% if pat_registered_at %}
Registered {{ pat_registered_at.strftime("%b %d, %Y") }}
{% else %}
Registered
{% endif %}
</p>
</div>
</div>
<form method="post" action="/settings/pat/delete">
<button type="submit"
class="btn btn-xs btn-secondary text-danger-foreground hover:bg-danger-muted hover:border-danger-muted">
Delete
</button>
</form>
</div>
</div>
<details class="mt-4">
<summary class="cursor-pointer text-sm text-muted-foreground hover:text-foreground">
Update token
</summary>
<form id="pat-form"
class="mt-3"
method="post"
action="/settings/pat"
novalidate>
<div class="grid gap-2 sm:gap-4 sm:grid-cols-[1fr_auto] sm:items-end">
<input type="password"
id="pat"
name="pat"
class="block w-full input-mono"
placeholder="Paste new token..."
aria-describedby="pat-error"
aria-invalid="false"
required />
<button type="submit" class="btn btn-sm btn-primary self-center">Update</button>
</div>
<div class="mt-2">
<p id="pat-error" class="input-error hidden">A Forgejo token is required.</p>
</div>
</form>
</details>
{% else %}
<form id="pat-form"
class="mt-4"
method="post"
action="/settings/pat"
novalidate>
<div class="grid gap-2 sm:gap-4 sm:grid-cols-[1fr_auto] sm:items-end">
<input type="password"
id="pat"
name="pat"
class="block w-full input-mono"
placeholder="ad8j3..."
aria-describedby="pat-error"
aria-invalid="false"
required />
<button type="submit" class="btn btn-sm btn-primary self-center">Register</button>
</div>
<div class="mt-2">
<p id="pat-error" class="input-error hidden">A Forgejo token is required.</p>
</div>
</form>
{% endif %}
</div>
</div>
<script>
(() => {
const form = document.getElementById("pat-form");
const input = document.getElementById("pat");
const error = document.getElementById("pat-error");
if (!form || !input || !error) return;
const showError = () => {
input.setAttribute("aria-invalid", "true");
input.classList.add("border-danger", "focus:border-danger", "focus:ring-danger-muted");
error.classList.remove("hidden");
input.focus();
};
const clearError = () => {
input.setAttribute("aria-invalid", "false");
input.classList.remove("border-danger", "focus:border-danger", "focus:ring-danger-muted");
error.classList.add("hidden");
};
form.addEventListener("submit", (event) => {
if (input.value.trim()) return;
event.preventDefault();
showError();
});
input.addEventListener("input", clearError);
})();
</script>
{% endblock %}