New accounts confirm their email address before signing in: sign-up mails a link valid for 24 hours, and its page confirms only when the visitor presses the button, so mail scanners opening links do not sign in. Confirming signs the account in; unconfirmed accounts are told so only after giving the right password, can ask for a new link, and are deleted after a week. UPTIME_SIGNUP_VERIFY requires confirmation always in the cloud edition and self-hosted wherever mail can be sent; without a mail server, sign-up that needs it stays closed. One account per mailbox: users.email_key drops +suffixes, and dots for Gmail, and is unique, including for accounts created through invitations and SSO, which count as confirmed. A client address (IPv6: its /64) may create UPTIME_SIGNUPS_PER_IP accounts a day, 2 by default; refused sign-ups do not count. Sign-up asks only for name, email and password. Accounts without an organization are led to create one; signed-in users create further organizations from the switcher, within the per-account limit, and POST /api/v1/orgs does the same. Closes #112 Closes #113 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
125 lines
4.9 KiB
Templ
125 lines
4.9 KiB
Templ
package web
|
|
|
|
import (
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
|
)
|
|
|
|
templ Login(p Page, signupAllowed bool, next string) {
|
|
@authShell(p) {
|
|
<form data-api="/auth/login" data-next={ next }>
|
|
@formError()
|
|
<div data-step="password">
|
|
@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>
|
|
<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>
|
|
}
|
|
}
|
|
}
|
|
|
|
templ Signup(p Page) {
|
|
@authShell(p) {
|
|
<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)
|
|
@submit(i18n.T(ctx, "auth.signup.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 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>
|
|
}
|
|
}
|
|
}
|