package web import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" // Me is the signed-in user as the console templates see it. type Me struct { // IsOwner refers to the active organization. IsOwner bool ActiveSlug string Email string DisplayName string TOTP bool ActiveOrg string Orgs []Org // Can holds the permissions in the active organization. Can map[string]bool // Policy is the error code of an unmet sign-in policy of the active // organization, or empty. Policy string // RecoveryCodesLeft counts unused TOTP recovery codes. RecoveryCodesLeft int } // Org is one entry of the organization switcher. type Org struct { ID string Name string Slug string IsOwner bool } templ consoleShell(p Page, me Me) { @Layout(p) {
uptimesebi if len(me.Orgs) > 1 { } else if len(me.Orgs) == 1 { { me.Orgs[0].Name } }
switch me.Policy { case "totp_required_by_org": @policyBanner("error.totp_required_by_org", "console.totp_missing_action", "/settings/security") case "sso_required_by_org": @policyBanner("error.sso_required_by_org", "console.sso_required_action", "/sso/"+me.ActiveSlug) }
@flash(p) { children... }
} } templ Dashboard(p Page, me Me) { @consoleShell(p, me) {

{ i18n.T(ctx, "console.monitors.title") }

{ i18n.T(ctx, "console.monitors.empty") }

} } // Identity is an SSO sign-in linked to the user in the active organization. type Identity struct { Provider string Email string } templ Security(p Page, me Me, identities []Identity, canLink bool) { @consoleShell(p, me) {

{ i18n.T(ctx, "security.title") }

{ i18n.T(ctx, "security.totp.heading") }

if me.TOTP {

● { i18n.T(ctx, "security.totp.active") }

= 3) }> { i18n.T(ctx, "security.recovery.left", "Count", me.RecoveryCodesLeft) }

{ i18n.T(ctx, "security.recovery.regenerate") }
@formError() @field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true) @field(i18n.T(ctx, "security.totp.current_code"), "code", "text", "one-time-code", true) @submit(i18n.T(ctx, "security.recovery.regenerate")) @recoveryOutput()
{ i18n.T(ctx, "security.totp.disable") }
@formError() @field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true) @field(i18n.T(ctx, "security.totp.current_code"), "code", "text", "one-time-code", true) @submit(i18n.T(ctx, "security.totp.disable"))
} else {

● { i18n.T(ctx, "security.totp.inactive") }

}

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

if len(identities) == 0 {

{ i18n.T(ctx, "security.sso.none") }

} else { } if canLink { { i18n.T(ctx, "security.sso.link") } }
} } // recoveryOutput is filled by app.js with codes returned by the API; they // are shown once and never rendered by the server. templ recoveryOutput() { } templ policyBanner(msgID, actionID, href string) {

{ i18n.T(ctx, msgID) } { i18n.T(ctx, actionID) }

}