Files
uptimesebi/internal/web/auth.templ
T
Sebastian UnterschützandClaude Opus 5.5 f3d402705e
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 7m0s
ci / test (pull_request) Successful in 12m1s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Successful in 5m9s
feat: support tickets between accounts and platform admins
Accounts open tickets under Support and admins answer them under Admin →
Support tickets.

- A ticket is open while it waits for the admins and answered while it
  waits for the account. Either side can close or reopen it, and a reply
  reopens it.
- The admins are mailed about new tickets and replies, and the account
  about answers.
- A ticket can name the active organization and point at a monitor,
  notification channel, alert group, status page or incident in it.
  Each must be something the account can read.
- Next to the conversation, admins see the account at a glance: state,
  sign-in, organizations with their limits and usage, and open tickets.
- Admins switch support off and limit how many tickets an account has
  open at once.
- Suspended accounts and those yet to accept the terms reach support too;
  a suspended account opens one ticket.
- Tickets are part of the account export and are deleted with the
  account.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-24 18:01:50 +01:00

264 lines
10 KiB
Templ

package web
import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
// IDPButton is a platform identity provider to sign in with.
type IDPButton struct {
URL, Name, Kind string
}
templ idpButtons(providers []IDPButton, labelID string) {
if len(providers) > 0 {
<div class="mb-8 grid gap-2">
for _, pr := range providers {
<a href={ templ.SafeURL(pr.URL) } class="block border border-ink px-3 py-2 text-center text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, labelID, "Name", pr.Name) }</a>
}
</div>
<p class="mb-6 text-center text-xs uppercase tracking-wider text-muted">{ i18n.T(ctx, "auth.or") }</p>
}
}
// Login signs in; mfa starts at the second factor, after a provider
// confirmed who it is.
templ Login(p Page, signupAllowed bool, next string, providers []IDPButton, mfa bool) {
@authShell(p) {
if !mfa {
@idpButtons(providers, "auth.sso.continue_with")
}
<form data-api="/auth/login" data-next={ next }>
@formError()
<div data-step="password" hidden?={ mfa }>
@field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true)
@field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true)
</div>
<div data-step="totp" hidden?={ !mfa }>
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "auth.login.totp_hint") }</p>
@field(i18n.T(ctx, "auth.field.code"), "code", "text", "one-time-code", false)
</div>
@submit(i18n.T(ctx, "auth.login.submit"))
</form>
<p class="mt-4 text-xs text-muted"><a href="/verify/resend" class="underline underline-offset-2 hover:text-ink">{ i18n.T(ctx, "auth.verify.resend_link") }</a></p>
<form action="/sso" method="get" class="mt-10 border-t border-rule pt-6">
<p class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "auth.sso.heading") }</p>
<div class="flex gap-2">
<input
class="min-w-0 flex-1 border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink"
name="org"
placeholder={ i18n.T(ctx, "auth.sso.org_placeholder") }
aria-label={ i18n.T(ctx, "auth.sso.org_placeholder") }
autocomplete="organization"
required
/>
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "auth.sso.submit") }</button>
</div>
</form>
if signupAllowed {
<p class="mt-8 text-sm text-muted">
{ i18n.T(ctx, "auth.login.no_account") }
<a class="text-ink underline underline-offset-2" href="/signup">{ i18n.T(ctx, "auth.login.to_signup") }</a>
</p>
}
}
}
// Signup offers the providers people may sign up through and, if email
// is set, the form for signing up with email and password.
// SignupConsent lists the documents a new account accepts and their
// versions, empty when the platform has none.
type SignupConsent struct {
Docs []LegalLink
Versions string
}
// consentLinks names the documents as links, opening in a new tab so a
// half-filled form survives reading them.
templ consentLinks(docs []LegalLink) {
for i, d := range docs {
if i > 0 {
{ i18n.T(ctx, "consent.and") }
}
<a href={ templ.SafeURL(d.Href) } target="_blank" rel="noopener" class="underline underline-offset-2">{ i18n.T(ctx, "consent.doc."+d.Kind) }</a>
}
}
// consentField is the checkbox a sign-up form needs ticked.
templ consentField(c SignupConsent) {
if len(c.Docs) > 0 {
<input type="hidden" name="consent_versions" value={ c.Versions }/>
<label class="mb-4 flex items-start gap-2 text-sm">
<input type="checkbox" name="consent" required class="mt-1 accent-ink"/>
<span>
{ i18n.T(ctx, "consent.accept_prefix") }
@consentLinks(c.Docs)
{ i18n.T(ctx, "consent.accept_suffix") }
</span>
</label>
}
}
templ Signup(p Page, providers []IDPButton, email bool, consent SignupConsent) {
@authShell(p) {
if email {
@idpButtons(providers, "auth.sso.signup_with")
<form data-api="/auth/signup" data-next="/">
@formError()
@field(i18n.T(ctx, "auth.field.name"), "display_name", "text", "name", false)
@field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true)
@field(i18n.T(ctx, "auth.field.new_password", "Min", auth.MinPasswordLength), "password", "password", "new-password", true)
@consentField(consent)
@submit(i18n.T(ctx, "auth.signup.submit"))
</form>
if len(consent.Docs) > 0 && len(providers) > 0 {
<p class="mt-4 text-xs text-muted">{ i18n.T(ctx, "consent.sso_hint") }</p>
}
} else {
<div class="grid gap-2">
for _, pr := range providers {
<a href={ templ.SafeURL(pr.URL) } class="block border border-ink px-3 py-2 text-center text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "auth.sso.signup_with", "Name", pr.Name) }</a>
}
</div>
}
<p class="mt-8 text-sm text-muted"><a class="text-ink underline underline-offset-2" href="/login">{ i18n.T(ctx, "auth.signup.to_login") }</a></p>
}
}
templ SignupSent(p Page) {
@authShell(p) {
<p class="text-sm">{ i18n.T(ctx, "auth.verify.sent") }</p>
<p class="mt-4 text-sm text-muted">{ i18n.T(ctx, "auth.verify.sent_hint") }</p>
<p class="mt-8 text-sm"><a href="/verify/resend" class="underline underline-offset-2">{ i18n.T(ctx, "auth.verify.resend_link") }</a></p>
}
}
// Verify confirms an address when the visitor presses the button.
templ Verify(p Page, token string) {
@authShell(p) {
if token == "" {
<p class="text-sm">{ i18n.T(ctx, "error.verification_expired") }</p>
<p class="mt-6 text-sm"><a href="/verify/resend" class="underline underline-offset-2">{ i18n.T(ctx, "auth.verify.resend_link") }</a></p>
} else {
<form data-api="/auth/verify" data-next="/">
@formError()
<input type="hidden" name="token" value={ token }/>
<p class="mb-6 text-sm">{ i18n.T(ctx, "auth.verify.intro") }</p>
@submit(i18n.T(ctx, "auth.verify.submit"))
</form>
<p class="mt-6 text-xs text-muted"><a href="/verify/resend" class="underline underline-offset-2 hover:text-ink">{ i18n.T(ctx, "auth.verify.resend_link") }</a></p>
}
}
}
templ ResendVerification(p Page) {
@authShell(p) {
<form data-api="/auth/verify/resend" data-next="/signup/sent">
@formError()
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "auth.verify.resend_intro") }</p>
@field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true)
@submit(i18n.T(ctx, "auth.verify.resend_submit"))
</form>
<p class="mt-8 text-sm text-muted"><a class="text-ink underline underline-offset-2" href="/login">{ i18n.T(ctx, "auth.signup.to_login") }</a></p>
}
}
templ newOrgForm() {
<form data-api="/orgs" data-next="/">
@formError()
@field(i18n.T(ctx, "auth.field.org_name"), "name", "text", "organization", true)
@field(i18n.T(ctx, "auth.field.org_slug"), "slug", "text", "off", true)
@submit(i18n.T(ctx, "orgs.create"))
</form>
}
// NewOrgPage creates an organization: the first, in a page of its own
// since there is no console yet, or another one.
templ NewOrgPage(p Page, me Me) {
if len(me.Orgs) == 0 {
@authShell(p) {
<p class="mb-6 text-sm text-muted">{ i18n.T(ctx, "orgs.first_intro") }</p>
@newOrgForm()
<p class="mt-8 text-sm text-muted">{ i18n.T(ctx, "orgs.invited_hint") }</p>
<button data-logout class="mt-4 text-sm underline underline-offset-2">{ i18n.T(ctx, "console.nav.logout") }</button>
}
} else {
@consoleShell(p, me) {
@settingsHeading("orgs.new_title", "orgs.new_intro")
<div class="max-w-sm">
@newOrgForm()
</div>
}
}
}
// ConsentPage asks a signed-in account to accept the platform's documents,
// new or changed. Declining leaves exporting and deleting the account.
templ ConsentPage(p Page, me Me, docs []LegalLink, versions, next string) {
@Layout(p) {
<main class="mx-auto mt-[8vh] w-full max-w-xl px-6 pb-16">
<div class="mb-10 flex items-center justify-between">
@brandLockup("/consent")
@languageSwitch(p.Languages)
</div>
<h1 class="mb-4 text-xl font-semibold">{ i18n.T(ctx, p.TitleID) }</h1>
<p class="mb-6 text-sm">{ i18n.T(ctx, "consent.intro") }</p>
<ul class="mb-6 list-inside list-disc text-sm">
for _, d := range docs {
<li><a href={ templ.SafeURL(d.Href) } target="_blank" rel="noopener" class="underline underline-offset-2">{ i18n.T(ctx, LegalTitleID(d.Kind)) }</a></li>
}
</ul>
<form data-api="/consent" data-next={ next }>
@formError()
<input type="hidden" name="versions" value={ versions }/>
<input type="hidden" name="next" value={ next }/>
<label class="mb-4 flex items-start gap-2 text-sm">
<input type="checkbox" name="accept" required class="mt-1 accent-ink"/>
<span>
{ i18n.T(ctx, "consent.accept_prefix") }
@consentLinks(docs)
{ i18n.T(ctx, "consent.accept_suffix") }
</span>
</label>
@submit(i18n.T(ctx, "consent.submit"))
</form>
<p class="mt-6 flex flex-wrap gap-x-4 text-sm">
if me.Support {
<a href="/support" class="underline underline-offset-2">{ i18n.T(ctx, "support.contact") }</a>
}
<button data-logout class="underline underline-offset-2">{ i18n.T(ctx, "console.nav.logout") }</button>
</p>
<div class="mt-12 border-t border-rule pt-6">
<p class="mb-6 text-sm text-muted">{ i18n.T(ctx, "consent.decline") }</p>
@accountDataBody(me)
</div>
</main>
}
}
// SuspendedPage is all a suspended account sees: why, and how to take its
// data along or delete it.
templ SuspendedPage(p Page, me Me, reason string) {
@Layout(p) {
<main class="mx-auto mt-[8vh] w-full max-w-xl px-6 pb-16">
<div class="mb-10 flex items-center justify-between">
@brandLockup("/account/suspended")
@languageSwitch(p.Languages)
</div>
<h1 class="mb-4 text-xl font-semibold">{ i18n.T(ctx, p.TitleID) }</h1>
<p class="mb-2 text-sm">{ i18n.T(ctx, "suspended.intro") }</p>
if reason != "" {
<p class="mb-6 border-l-2 border-down pl-3 text-sm">{ reason }</p>
}
<p class="mb-6 text-sm text-muted">{ i18n.T(ctx, "suspended.options") }</p>
<p class="mb-10 flex flex-wrap gap-x-4 text-sm">
if me.Support {
<a href="/support" class="underline underline-offset-2">{ i18n.T(ctx, "support.contact") }</a>
}
<button data-logout class="underline underline-offset-2">{ i18n.T(ctx, "console.nav.logout") }</button>
</p>
@accountDataBody(me)
</main>
}
}