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. templ Signup(p Page, providers []IDPButton, email bool) { @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) @submit(i18n.T(ctx, "auth.signup.submit"))
} 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()
} } }