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 {
for _, pr := range providers { { i18n.T(ctx, labelID, "Name", pr.Name) } }

{ i18n.T(ctx, "auth.or") }

} } // 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") }
@formError()
@field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true) @field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true)

{ i18n.T(ctx, "auth.login.totp_hint") }

@field(i18n.T(ctx, "auth.field.code"), "code", "text", "one-time-code", false)
@submit(i18n.T(ctx, "auth.login.submit"))

{ i18n.T(ctx, "auth.verify.resend_link") }

{ i18n.T(ctx, "auth.sso.heading") }

if signupAllowed {

{ i18n.T(ctx, "auth.login.no_account") } { i18n.T(ctx, "auth.login.to_signup") }

} } } // 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") } } { i18n.T(ctx, "consent.doc."+d.Kind) } } } // consentField is the checkbox a sign-up form needs ticked. templ consentField(c SignupConsent) { if len(c.Docs) > 0 { } } templ Signup(p Page, providers []IDPButton, email bool, consent SignupConsent) { @authShell(p) { if email { @idpButtons(providers, "auth.sso.signup_with")
@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"))
if len(consent.Docs) > 0 && len(providers) > 0 {

{ i18n.T(ctx, "consent.sso_hint") }

} } else {
for _, pr := range providers { { i18n.T(ctx, "auth.sso.signup_with", "Name", pr.Name) } }
}

{ i18n.T(ctx, "auth.signup.to_login") }

} } templ SignupSent(p Page) { @authShell(p) {

{ i18n.T(ctx, "auth.verify.sent") }

{ i18n.T(ctx, "auth.verify.sent_hint") }

{ i18n.T(ctx, "auth.verify.resend_link") }

} } // Verify confirms an address when the visitor presses the button. templ Verify(p Page, token string) { @authShell(p) { if token == "" {

{ i18n.T(ctx, "error.verification_expired") }

{ i18n.T(ctx, "auth.verify.resend_link") }

} else {
@formError()

{ i18n.T(ctx, "auth.verify.intro") }

@submit(i18n.T(ctx, "auth.verify.submit"))

{ i18n.T(ctx, "auth.verify.resend_link") }

} } } templ ResendVerification(p Page) { @authShell(p) {
@formError()

{ i18n.T(ctx, "auth.verify.resend_intro") }

@field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true) @submit(i18n.T(ctx, "auth.verify.resend_submit"))

{ i18n.T(ctx, "auth.signup.to_login") }

} } templ newOrgForm() {
@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"))
} // 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) {

{ i18n.T(ctx, "orgs.first_intro") }

@newOrgForm()

{ i18n.T(ctx, "orgs.invited_hint") }

} } else { @consoleShell(p, me) { @settingsHeading("orgs.new_title", "orgs.new_intro")
@newOrgForm()
} } } // 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) {
@brandLockup("/consent") @languageSwitch(p.Languages)

{ i18n.T(ctx, p.TitleID) }

{ i18n.T(ctx, "consent.intro") }

@formError() @submit(i18n.T(ctx, "consent.submit"))

if me.Support { { i18n.T(ctx, "support.contact") } }

{ i18n.T(ctx, "consent.decline") }

@accountDataBody(me)
} } // 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) {
@brandLockup("/account/suspended") @languageSwitch(p.Languages)

{ i18n.T(ctx, p.TitleID) }

{ i18n.T(ctx, "suspended.intro") }

if reason != "" {

{ reason }

}

{ i18n.T(ctx, "suspended.options") }

if me.Support { { i18n.T(ctx, "support.contact") } }

@accountDataBody(me)
} }