feat(api): add signup, login with totp and account security pages
Signup is limited to the first user by default (UPTIME_SIGNUP). TOTP secrets are sealed with UPTIME_SECRET_KEYS and bound to the user id. Closes #3 Closes #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
99e9b1e57d
commit
db44fedc72
18 files changed
+1792
-91
No files matched your search
@@ -0,0 +1,90 @@
|
||||
package web
|
||||
|
||||
type Me struct {
|
||||
Email string
|
||||
DisplayName string
|
||||
TOTP bool
|
||||
ActiveOrg string
|
||||
Orgs []Org
|
||||
TOTPMissing bool
|
||||
}
|
||||
|
||||
type Org struct {
|
||||
ID string
|
||||
Name string
|
||||
Slug string
|
||||
IsOwner bool
|
||||
}
|
||||
|
||||
templ consoleShell(p Page, me Me) {
|
||||
@Layout(p) {
|
||||
<header class="border-b border-rule">
|
||||
<div class="mx-auto flex max-w-5xl items-center gap-6 px-6 py-3 text-sm">
|
||||
<a href="/" class="font-mono text-xs tracking-wide">uptimesebi</a>
|
||||
if len(me.Orgs) > 1 {
|
||||
<select data-switch-org class="border border-rule bg-transparent px-1.5 py-0.5 text-sm">
|
||||
for _, o := range me.Orgs {
|
||||
<option value={ o.ID } selected?={ o.ID == me.ActiveOrg }>{ o.Name }</option>
|
||||
}
|
||||
</select>
|
||||
} else if len(me.Orgs) == 1 {
|
||||
<span class="text-muted">{ me.Orgs[0].Name }</span>
|
||||
}
|
||||
<nav class="ml-auto flex items-center gap-5">
|
||||
<a href="/settings/security" class="text-muted hover:text-ink">Sicherheit</a>
|
||||
<button data-logout class="text-muted hover:text-ink">Abmelden</button>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
if me.TOTPMissing {
|
||||
<div class="border-b border-degraded/40 bg-degraded/10">
|
||||
<p class="mx-auto max-w-5xl px-6 py-2 text-sm">
|
||||
Deine Organisation verlangt Zwei-Faktor-Anmeldung.
|
||||
<a href="/settings/security" class="underline underline-offset-2">Jetzt einrichten</a>
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
<main class="mx-auto max-w-5xl px-6 py-10">
|
||||
{ children... }
|
||||
</main>
|
||||
}
|
||||
}
|
||||
|
||||
templ Dashboard(p Page, me Me) {
|
||||
@consoleShell(p, me) {
|
||||
<h1 class="text-lg font-semibold">Monitore</h1>
|
||||
<p class="mt-2 text-sm text-muted">Noch keine Monitore angelegt.</p>
|
||||
}
|
||||
}
|
||||
|
||||
templ Security(p Page, me Me) {
|
||||
@consoleShell(p, me) {
|
||||
<h1 class="mb-8 text-lg font-semibold">Sicherheit</h1>
|
||||
<section class="max-w-md">
|
||||
<h2 class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">Zwei-Faktor (TOTP)</h2>
|
||||
if me.TOTP {
|
||||
<p class="mb-6 text-sm"><span class="text-up">●</span> aktiv</p>
|
||||
<form data-api="/me/totp/disable" data-next="/settings/security">
|
||||
@formError()
|
||||
@field("Passwort", "password", "password", "current-password", true)
|
||||
@field("Aktueller Code", "code", "text", "one-time-code", true)
|
||||
@submit("Deaktivieren")
|
||||
</form>
|
||||
} else {
|
||||
<p class="mb-6 text-sm"><span class="text-unknown">●</span> nicht eingerichtet</p>
|
||||
<div data-totp-setup>
|
||||
<button data-totp-start class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">Einrichten</button>
|
||||
<div data-totp-panel hidden>
|
||||
<img data-totp-qr alt="QR-Code für die Authenticator-App" class="mb-3 h-48 w-48 border border-rule bg-white p-2"/>
|
||||
<p class="mb-6 break-all font-mono text-xs text-muted" data-totp-secret></p>
|
||||
<form data-api="/me/totp/enable" data-next="/settings/security">
|
||||
@formError()
|
||||
@field("Code aus der App", "code", "text", "one-time-code", true)
|
||||
@submit("Bestätigen")
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user