diff --git a/.env.example b/.env.example index 17e4ad5..98d38e4 100644 --- a/.env.example +++ b/.env.example @@ -13,6 +13,17 @@ UPTIME_PUBLIC_URL=http://localhost:8080 # auto = allowed for UPTIME_EDITION=selfhosted, denied for cloud. UPTIME_SSO_ALLOW_PRIVATE_NETWORKS=auto +# Who may sign up: first-user (only the operator of a fresh installation), +# open or closed. New accounts confirm their email address before signing in: +# auto = always in the cloud edition, self-hosted only when UPTIME_SMTP_URL is +# set; required; off (self-hosted only). Sign-ups per client address (IPv6: +# per /64) in 24 hours, 0 = unlimited. +# UPTIME_SIGNUP=first-user +# UPTIME_SIGNUP_VERIFY=auto +# UPTIME_SIGNUPS_PER_IP=2 +# Outgoing mail, for email channels and sign-up confirmation. +# UPTIME_SMTP_URL=smtp://user:pass@mail.example.com:587?from=uptime@example.com + # Checker and status page reach the API only. Create tokens with: # api agent create --kind checker --region local --name dev # api agent create --kind statuspage --name dev diff --git a/README.md b/README.md index 33d37d4..cfba226 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ All settings are environment variables; [`.env.example`](.env.example) lists the - `UPTIME_SECRET_KEYS` encrypts stored secrets. Generate one with `echo "k1:$(head -c32 /dev/urandom | base64)"` and keep it safe; rotate by prepending a new key. - `UPTIME_PUBLIC_URL` is the address users reach the console at. +- `UPTIME_SIGNUP` (`first-user`, `open`, `closed`) decides who may sign up. New accounts confirm their email address before signing in (`UPTIME_SIGNUP_VERIFY`: always in the cloud edition, self-hosted when `UPTIME_SMTP_URL` is set); one account per mailbox, and at most `UPTIME_SIGNUPS_PER_IP` (default 2) a day per client address. - `UPTIME_TRUSTED_PROXIES` must name your reverse proxy, or client addresses in the audit log and rate limits will be the proxy's. - `UPTIME_RETENTION_*` set how long results, aggregates, audit entries and captured responses are kept. diff --git a/internal/api/alerting_test.go b/internal/api/alerting_test.go index 25767e2..e1fedf5 100644 --- a/internal/api/alerting_test.go +++ b/internal/api/alerting_test.go @@ -60,7 +60,7 @@ func (r *receiver) kinds() []string { func TestAlerting(t *testing.T) { mail := notifytest.NewSMTP(t) - e := newEnvWith(t, func(c *config.API) { c.SMTPURL = mail.URL() }) + e := newEnvWith(t, func(c *config.API) { c.SMTPURL, c.SignupVerify = mail.URL(), "off" }) ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) go e.api.RunScheduler(ctx) diff --git a/internal/api/apidocs.go b/internal/api/apidocs.go index 1f337f1..b264f32 100644 --- a/internal/api/apidocs.go +++ b/internal/api/apidocs.go @@ -22,9 +22,18 @@ func paged(o obj) obj { // show them. var endpoints = []endpoint{ // Account - {method: "POST", path: "/api/v1/auth/signup", tag: "Account", summary: "Create an account and organization", public: true, - description: "Starts a session. Depending on the installation, sign-up is open, limited to the first user, or closed.", + {method: "POST", path: "/api/v1/auth/signup", tag: "Account", summary: "Create an account", public: true, + description: "Depending on the installation, sign-up is open, limited to the first user, or closed. Where addresses are confirmed, answers `{\"status\": \"verification_sent\"}` and mails a link; the account signs in after confirming. Otherwise starts a session, and `org_name`/`org_slug`, if given, create a first organization. One account per mailbox (+suffixes and Gmail dots count as the same address); a client address may create only a few accounts a day (`429 signup_limit`).", req: signupRequest{}, resp: sessionStarted}, + {method: "POST", path: "/api/v1/auth/verify", tag: "Account", summary: "Confirm an email address with the mailed token", public: true, + description: "Signs the account in. Tokens are valid for 24 hours and once; `410 verification_expired` otherwise.", + req: verifyRequest{}, resp: sessionStarted}, + {method: "POST", path: "/api/v1/auth/verify/resend", tag: "Account", summary: "Mail a new confirmation link", public: true, + description: "Answers the same whether or not an unconfirmed account with that address exists.", + req: resendRequest{}, status: http.StatusNoContent}, + {method: "POST", path: "/api/v1/orgs", tag: "Account", summary: "Create an organization", sessionOnly: true, + description: "The account owns it, and it becomes the active organization. Limited per account by the platform (`422 org_limit`).", + req: createOrgRequest{}, status: http.StatusCreated, resp: obj{"id": uuid.UUID{}, "slug": "", "redirect": ""}}, {method: "POST", path: "/api/v1/auth/login", tag: "Account", summary: "Sign in with email and password", public: true, description: "Answers `{\"status\": \"totp_required\"}` when the account has two-factor authentication; continue with /auth/login/totp.", req: loginRequest{}, resp: sessionStarted}, diff --git a/internal/api/audit.go b/internal/api/audit.go index 9ed5c3c..4e0549a 100644 --- a/internal/api/audit.go +++ b/internal/api/audit.go @@ -31,6 +31,9 @@ var auditActions = map[string]string{ "POST /api/v1/locale": "", "POST /api/v1/markdown/preview": "", "POST /api/v1/auth/signup": "account.signup", + "POST /api/v1/auth/verify": "account.verify", + "POST /api/v1/auth/verify/resend": "", + "POST /api/v1/orgs": "org.create", "POST /api/v1/auth/login": "auth.login", "POST /api/v1/auth/login/totp": "auth.login", "POST /api/v1/auth/logout": "auth.logout", diff --git a/internal/api/auth.go b/internal/api/auth.go index 0af810f..e342f48 100644 --- a/internal/api/auth.go +++ b/internal/api/auth.go @@ -30,8 +30,11 @@ type signupRequest struct { Email string `json:"email" binding:"required,email,max=320"` Password string `json:"password" binding:"required,max=1024"` DisplayName string `json:"display_name" binding:"max=200"` - OrgName string `json:"org_name" binding:"required,max=200"` - OrgSlug string `json:"org_slug" binding:"required,max=63"` + // OrgName and OrgSlug create a first organization at once, when no + // email confirmation is needed; otherwise the account creates one + // after confirming. + OrgName string `json:"org_name" binding:"max=200"` + OrgSlug string `json:"org_slug" binding:"max=63"` } func (s *Server) signup(c *gin.Context) { @@ -50,6 +53,15 @@ func (s *Server) signup(c *gin.Context) { fail(c, http.StatusForbidden, "signup_closed") return } + if left, err := s.signupsLeft(c); err != nil { + internalError(c, err) + return + } else if !left { + fail(c, http.StatusTooManyRequests, "signup_limit") + return + } + verify := s.verificationRequired() + withOrg := !verify && strings.TrimSpace(req.OrgName) != "" && strings.TrimSpace(req.OrgSlug) != "" hash, err := auth.HashPassword(req.Password) if errors.Is(err, auth.ErrPasswordTooShort) { fail(c, http.StatusUnprocessableEntity, "password_too_short", "Min", auth.MinPasswordLength) @@ -63,20 +75,27 @@ func (s *Server) signup(c *gin.Context) { var user store.User err = s.db.Tx(ctx, tenant.Org(orgID, uuid.Nil), func(q *store.Queries) error { var err error - user, err = q.CreateUser(ctx, store.CreateUserParams{ + params := store.CreateUserParams{ Email: normalizeEmail(req.Email), DisplayName: strings.TrimSpace(req.DisplayName), PasswordHash: &hash, Locale: ptr(i18n.Lang(ctx)), - }) + EmailKey: ptr(emailKey(req.Email)), + } + if !verify { + params.EmailVerifiedAt = ptr(time.Now()) + } + user, err = q.CreateUser(ctx, params) if err != nil { return err } - if _, err := q.CreateOrg(ctx, store.CreateOrgParams{ID: orgID, Slug: strings.ToLower(req.OrgSlug), Name: strings.TrimSpace(req.OrgName)}); err != nil { - return err - } - if err := q.AddMembership(ctx, store.AddMembershipParams{OrgID: orgID, UserID: user.ID, IsOwner: true}); err != nil { - return err + if withOrg { + if _, err := q.CreateOrg(ctx, store.CreateOrgParams{ID: orgID, Slug: strings.ToLower(req.OrgSlug), Name: strings.TrimSpace(req.OrgName)}); err != nil { + return err + } + if err := q.AddMembership(ctx, store.AddMembershipParams{OrgID: orgID, UserID: user.ID, IsOwner: true}); err != nil { + return err + } } // Whoever sets up a self-hosted installation operates it. if s.cfg.Signup == config.SignupFirstUser && s.cfg.Edition == config.EditionSelfHosted { @@ -85,7 +104,7 @@ func (s *Server) signup(c *gin.Context) { return nil }) switch { - case isUniqueViolation(err, "users_email_key"): + case isUniqueViolation(err, "users_email_key"), isUniqueViolation(err, "users_email_key_idx"): fail(c, http.StatusConflict, "email_taken") return case isUniqueViolation(err, "orgs_slug_key"): @@ -98,10 +117,27 @@ func (s *Server) signup(c *gin.Context) { internalError(c, err) return } + s.countSignup(c) + if verify { + auditActor(c, user.ID) + if err := s.sendVerification(ctx, user); err != nil { + s.log.ErrorContext(ctx, "sending verification failed", "error", err) + fail(c, http.StatusBadGateway, "verification_mail_failed") + return + } + c.JSON(http.StatusOK, gin.H{"status": "verification_sent", "redirect": "/signup/sent"}) + return + } + if !withOrg { + orgID = uuid.Nil + } s.startSession(c, auth.NewSession{UserID: user.ID, OrgID: orgID, Locale: i18n.Lang(ctx), Method: auth.MethodPassword}) } func (s *Server) signupAllowed(ctx context.Context) (bool, error) { + if s.signupClosedWithoutMail() { + return false, nil + } switch s.cfg.Signup { case config.SignupOpen: return true, nil @@ -159,11 +195,16 @@ func (s *Server) login(c *gin.Context) { invalidCredentials(c) return } - // Only someone who knows the password learns of the suspension. + // Only someone who knows the password learns of the suspension or a + // missing confirmation. if user.DisabledAt != nil { fail(c, http.StatusForbidden, "account_suspended") return } + if user.EmailVerifiedAt == nil { + fail(c, http.StatusForbidden, "email_unverified") + return + } if rehash { s.rehashPassword(ctx, user.ID, req.Password) } diff --git a/internal/api/checkernet_test.go b/internal/api/checkernet_test.go index a213fa6..6052d2c 100644 --- a/internal/api/checkernet_test.go +++ b/internal/api/checkernet_test.go @@ -35,7 +35,7 @@ func latestOf(b *browser, id string) (bool, string, bool) { func TestCheckerNetwork(t *testing.T) { // In the cloud edition, platform checkers stay off private networks // unless an admin allows it. - cloud := newEnvWith(t, func(c *config.API) { c.Edition = config.EditionCloud }) + cloud := newEnvWith(t, func(c *config.API) { c.Edition, c.SignupVerify = config.EditionCloud, "off" }) e := newEnv(t) ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) diff --git a/internal/api/console.go b/internal/api/console.go index df98214..537e614 100644 --- a/internal/api/console.go +++ b/internal/api/console.go @@ -63,6 +63,11 @@ func (s *Server) dashboard(c *gin.Context) { internalError(c, err) return } + if len(me.Orgs) == 0 { + // New accounts start by creating an organization. + c.Redirect(http.StatusSeeOther, "/orgs/new") + return + } v := web.DashboardView{Counts: map[web.Status]int{}, Empty: true} if p != nil && me.Policy == "" { data, err := s.loadMonitorData(c.Request.Context(), p, web.RangeByKey(c.Query("range"))) diff --git a/internal/api/housekeeping.go b/internal/api/housekeeping.go index b0c8e43..850e0be 100644 --- a/internal/api/housekeeping.go +++ b/internal/api/housekeeping.go @@ -47,7 +47,7 @@ func (s *Server) RunHousekeeping(ctx context.Context) { // tokens and incidents older than the daily aggregate. func (s *Server) Housekeep(ctx context.Context, now time.Time) error { keep := s.cfg.Retention - var counts [6]int64 + var counts [7]int64 err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { var err error if keep.Housekeeping > 0 { @@ -75,15 +75,19 @@ func (s *Server) Housekeep(ctx context.Context, now time.Time) error { if _, err = q.PurgeAlertmanagerAlerts(ctx, now.Add(-keepAlerts)); err != nil { return err } + if counts[6], err = q.PurgeUnverifiedUsers(ctx, now.Add(-unverifiedKeep)); err != nil { + return err + } if keep.Daily > 0 { before := now.Add(-keep.Daily) counts[3], err = q.PurgeIncidents(ctx, &before) } return err }) - if err == nil && counts != [6]int64{} { + if err == nil && counts != [7]int64{} { s.log.InfoContext(ctx, "housekeeping purged rows", - "notifications", counts[0], "invitations", counts[1], "api_tokens", counts[2], "incidents", counts[3], "audit_events", counts[4], "evidence", counts[5]) + "notifications", counts[0], "invitations", counts[1], "api_tokens", counts[2], "incidents", counts[3], "audit_events", counts[4], "evidence", counts[5], + "unverified_accounts", counts[6]) } return err } diff --git a/internal/api/invitations.go b/internal/api/invitations.go index 16142ef..3a80c60 100644 --- a/internal/api/invitations.go +++ b/internal/api/invitations.go @@ -279,13 +279,16 @@ func (s *Server) inviteSignup(c *gin.Context) { } var user store.User err = s.db.Tx(ctx, tenant.Global(), func(q *store.Queries) error { + // The organization invited this address, which stands in for + // confirming it. user, err = q.CreateUser(ctx, store.CreateUserParams{ Email: inv.Email, DisplayName: strings.TrimSpace(req.DisplayName), PasswordHash: &hash, Locale: ptr(i18n.Lang(ctx)), + EmailKey: ptr(emailKey(inv.Email)), EmailVerifiedAt: ptr(time.Now()), }) return err }) - if isUniqueViolation(err, "users_email_key") { + if isUniqueViolation(err, "users_email_key") || isUniqueViolation(err, "users_email_key_idx") { fail(c, http.StatusConflict, "email_taken") return } diff --git a/internal/api/pages.go b/internal/api/pages.go index d8ca332..8771eaf 100644 --- a/internal/api/pages.go +++ b/internal/api/pages.go @@ -27,6 +27,10 @@ import ( func (s *Server) registerPages(r gin.IRouter) { r.GET("/login", s.loginPage) r.GET("/signup", s.signupPage) + r.GET("/signup/sent", s.signupSentPage) + r.GET("/verify", s.verifyPage) + r.GET("/verify/resend", s.resendPage) + r.GET("/orgs/new", s.newOrgPage) r.GET("/invite/:token", s.invitePage) s.registerConsole(r) r.GET("/settings/security", s.securityPage) @@ -105,6 +109,36 @@ func (s *Server) signupPage(c *gin.Context) { web.Render(c, http.StatusOK, web.Signup(s.pageFor(c, "auth.signup.title"))) } +func (s *Server) signupSentPage(c *gin.Context) { + web.Render(c, http.StatusOK, web.SignupSent(s.pageFor(c, "auth.verify.sent_title"))) +} + +// verifyPage confirms an address only when the visitor presses the +// button: mail scanners that open links must not sign in. +func (s *Server) verifyPage(c *gin.Context) { + web.Render(c, http.StatusOK, web.Verify(s.pageFor(c, "auth.verify.title"), c.Query("token"))) +} + +func (s *Server) resendPage(c *gin.Context) { + web.Render(c, http.StatusOK, web.ResendVerification(s.pageFor(c, "auth.verify.resend_title"))) +} + +// newOrgPage lets a signed-in account create an organization: the first +// one after signing up, or another. +func (s *Server) newOrgPage(c *gin.Context) { + sess := auth.Current(c) + if sess == nil { + c.Redirect(http.StatusSeeOther, "/login?next=/orgs/new") + return + } + me, _, err := s.consoleMe(c, sess) + if err != nil { + internalError(c, err) + return + } + web.Render(c, http.StatusOK, web.NewOrgPage(s.pageFor(c, "orgs.new_title"), me)) +} + // consoleMe loads the signed-in user and, if an organization is active, // their permissions and policy state there. The principal is nil when the // user has no active organization or is no longer a member. diff --git a/internal/api/paging_internal_test.go b/internal/api/paging_internal_test.go index 2ea3e8c..8f375f9 100644 --- a/internal/api/paging_internal_test.go +++ b/internal/api/paging_internal_test.go @@ -73,3 +73,22 @@ func TestPageSlice(t *testing.T) { t.Errorf("first %v, second %v, back %v", first, second, back) } } + +func TestEmailKey(t *testing.T) { + for in, want := range map[string]string{ + "Max.Power+uptime@googlemail.com": "maxpower@gmail.com", + "max.power@gmail.com": "maxpower@gmail.com", + "a.b+c@example.com": "a.b@example.com", + "A.B@Example.com": "a.b@example.com", + } { + if got := emailKey(in); got != want { + t.Errorf("emailKey(%q) = %q, want %q", in, got, want) + } + } + if clientKey("2001:db8:1:2:aaaa::1") != clientKey("2001:db8:1:2:bbbb::9") || clientKey("2001:db8:1:3::1") == clientKey("2001:db8:1:2::1") { + t.Error("IPv6 clients are not grouped by /64") + } + if clientKey("203.0.113.7") != "203.0.113.7" { + t.Error("IPv4 clients are grouped") + } +} diff --git a/internal/api/server.go b/internal/api/server.go index 97e9700..be0b89a 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -108,6 +108,9 @@ func (s *Server) Mount(r gin.IRouter) { a := v1.Group("/auth") a.POST("/signup", s.signup) + a.POST("/verify", s.verifyEmail) + a.POST("/verify/resend", s.resendVerification) + v1.POST("/orgs", auth.Require(), s.createOrg) a.POST("/login", s.login) a.POST("/login/totp", s.loginTOTP) a.POST("/logout", s.logout) diff --git a/internal/api/signup.go b/internal/api/signup.go new file mode 100644 index 0000000..a0c2f3b --- /dev/null +++ b/internal/api/signup.go @@ -0,0 +1,270 @@ +package api + +import ( + "context" + "crypto/sha256" + "encoding/hex" + "errors" + "net" + "net/http" + "net/url" + "strings" + "time" + + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + "github.com/redis/go-redis/v9" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/auth" + "git.zb-server.de/ZB-Server/uptimesebi/internal/notify" + "git.zb-server.de/ZB-Server/uptimesebi/internal/store" + "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" +) + +// New accounts confirm their email address before signing in, through a +// link mailed to them. One mailbox holds one account, aliases included, +// and a client address may create only a few accounts a day. + +const ( + verifyTTL = 24 * time.Hour + // unverifiedKeep is how long an account waits for confirmation. + unverifiedKeep = 7 * 24 * time.Hour +) + +// emailKey identifies the mailbox behind an address: +suffixes are dropped +// everywhere, and Gmail ignores dots and treats googlemail.com as gmail.com. +// The migration adding users.email_key computes the same. +func emailKey(email string) string { + local, domain, ok := strings.Cut(strings.ToLower(strings.TrimSpace(email)), "@") + if !ok { + return strings.ToLower(email) + } + local, _, _ = strings.Cut(local, "+") + if domain == "gmail.com" || domain == "googlemail.com" { + local, domain = strings.ReplaceAll(local, ".", ""), "gmail.com" + } + return local + "@" + domain +} + +// clientKey groups client addresses for sign-up limits: IPv6 clients +// usually hold a whole /64. +func clientKey(ip string) string { + a := net.ParseIP(ip) + if a == nil || a.To4() != nil { + return ip + } + return a.Mask(net.CIDRMask(64, 128)).String() + "/64" +} + +// verificationRequired reports whether new accounts confirm their email. +func (s *Server) verificationRequired() bool { + switch s.cfg.SignupVerify { + case "required": + return true + case "off": + return false + } + return s.cloud() || s.smtp != nil +} + +// signupsLeft reports whether the client may create another account. +func (s *Server) signupsLeft(c *gin.Context) (bool, error) { + if s.cfg.SignupsPerIP == 0 { + return true, nil + } + n, err := s.rdb.Get(c.Request.Context(), "signups:"+clientKey(c.ClientIP())).Int() + if errors.Is(err, redis.Nil) { + return true, nil + } + return n < s.cfg.SignupsPerIP, err +} + +// countSignup counts a created account against the client's daily limit. +func (s *Server) countSignup(c *gin.Context) { + if s.cfg.SignupsPerIP == 0 { + return + } + ctx := c.Request.Context() + key := "signups:" + clientKey(c.ClientIP()) + pipe := s.rdb.TxPipeline() + pipe.Incr(ctx, key) + pipe.ExpireNX(ctx, key, 24*time.Hour) + if _, err := pipe.Exec(ctx); err != nil { + s.log.WarnContext(ctx, "counting sign-up failed", "error", err) + } +} + +func verifyKey(token string) string { + sum := sha256.Sum256([]byte(token)) + return "verify:" + hex.EncodeToString(sum[:]) +} + +// sendVerification mails u a link that confirms their address. +func (s *Server) sendVerification(ctx context.Context, u store.User) error { + if s.smtp == nil { + return errors.New("api: no mail server to send verification") + } + token := auth.RandomToken() + if err := s.rdb.Set(ctx, verifyKey(token), u.ID.String(), verifyTTL).Err(); err != nil { + return err + } + l := s.catalog.Match(deref(u.Locale)) + link := strings.TrimSuffix(s.cfg.PublicURL, "/") + "/verify?token=" + url.QueryEscape(token) + data := map[string]any{"Link": link, "Hours": int(verifyTTL.Hours())} + return s.smtp.Send(ctx, notify.Mail{ + To: []string{u.Email}, Subject: l.T("email.verify.subject", data), Body: l.T("email.verify.body", data), + }) +} + +type verifyRequest struct { + Token string `json:"token" binding:"required,max=200"` +} + +// verifyEmail confirms the address the token was mailed to and signs the +// account in: whoever holds the link controls the mailbox. +func (s *Server) verifyEmail(c *gin.Context) { + var req verifyRequest + if !bind(c, &req) { + return + } + ctx := c.Request.Context() + if !s.limit(c, "verify:ip:"+c.ClientIP(), 30, 15*time.Minute) { + return + } + raw, err := s.rdb.GetDel(ctx, verifyKey(req.Token)).Result() + id, perr := uuid.Parse(raw) + if errors.Is(err, redis.Nil) || perr != nil { + fail(c, http.StatusGone, "verification_expired") + return + } + if err != nil { + internalError(c, err) + return + } + var u store.User + err = s.db.Tx(ctx, tenant.Global(), func(q *store.Queries) error { + var err error + u, err = q.MarkEmailVerified(ctx, id) + return err + }) + if errors.Is(err, pgx.ErrNoRows) { + fail(c, http.StatusGone, "verification_expired") + return + } + if err != nil { + internalError(c, err) + return + } + auditActor(c, u.ID) + if u.DisabledAt != nil { + fail(c, http.StatusForbidden, "account_suspended") + return + } + s.finishLogin(c, u.ID, auth.MethodPassword) +} + +type resendRequest struct { + Email string `json:"email" binding:"required,email,max=320"` +} + +// resendVerification mails a new link to an unconfirmed account. It +// answers the same whether or not such an account exists. +func (s *Server) resendVerification(c *gin.Context) { + var req resendRequest + if !bind(c, &req) { + return + } + ctx := c.Request.Context() + email := normalizeEmail(req.Email) + if !s.limit(c, "resend:ip:"+c.ClientIP(), 10, time.Hour) || !s.limit(c, "resend:email:"+email, 3, time.Hour) { + return + } + var u store.User + err := s.db.Tx(ctx, tenant.Global(), func(q *store.Queries) error { + var err error + u, err = q.GetUserByEmail(ctx, email) + return err + }) + switch { + case errors.Is(err, pgx.ErrNoRows): + case err != nil: + internalError(c, err) + return + case u.EmailVerifiedAt == nil && u.DisabledAt == nil: + if err := s.sendVerification(ctx, u); err != nil { + s.log.ErrorContext(ctx, "sending verification failed", "error", err) + } + } + c.Status(http.StatusNoContent) +} + +type createOrgRequest struct { + Name string `json:"name" binding:"required,max=200"` + Slug string `json:"slug" binding:"required,max=63"` +} + +// createOrg creates an organization owned by the signed-in account and +// makes it the active one. +func (s *Server) createOrg(c *gin.Context) { + var req createOrgRequest + if !bind(c, &req) { + return + } + sess := auth.Current(c) + ctx := c.Request.Context() + u, err := s.loadUser(ctx, sess.UserID) + if err != nil { + internalError(c, err) + return + } + max := s.platformLimits(ctx).OrgsPerAccount + if u.LimitOrgs != nil { + max = int(*u.LimitOrgs) + } + orgID := uuid.New() + err = s.db.Tx(ctx, tenant.Org(orgID, sess.UserID), func(q *store.Queries) error { + if max > 0 { + // Serialize the account's creations to count them reliably. + if err := q.LockOrgUsage(ctx, u.ID); err != nil { + return err + } + n, err := q.CountOwnedOrgs(ctx, u.ID) + if err != nil { + return err + } + if n >= int64(max) { + return limitError{"org_limit", max} + } + } + if _, err := q.CreateOrg(ctx, store.CreateOrgParams{ID: orgID, Slug: strings.ToLower(strings.TrimSpace(req.Slug)), Name: strings.TrimSpace(req.Name)}); err != nil { + return err + } + return q.AddMembership(ctx, store.AddMembershipParams{OrgID: orgID, UserID: u.ID, IsOwner: true}) + }) + switch { + case failLimit(c, err): + return + case isUniqueViolation(err, "orgs_slug_key"): + fail(c, http.StatusConflict, "slug_taken") + return + case isCheckViolation(err): + fail(c, http.StatusUnprocessableEntity, "invalid_slug") + return + case err != nil: + internalError(c, err) + return + } + auditOrg(c, orgID) + if err := s.sessions.SwitchOrg(ctx, sess, orgID); err != nil { + internalError(c, err) + return + } + c.JSON(http.StatusCreated, gin.H{"id": orgID, "slug": strings.ToLower(strings.TrimSpace(req.Slug)), "redirect": "/"}) +} + +// signupClosedWithoutMail tells whether sign-up must wait for a mail +// server: accounts need confirming but no link could be sent. +func (s *Server) signupClosedWithoutMail() bool { + return s.verificationRequired() && s.smtp == nil +} diff --git a/internal/api/signup_test.go b/internal/api/signup_test.go new file mode 100644 index 0000000..92f99d1 --- /dev/null +++ b/internal/api/signup_test.go @@ -0,0 +1,138 @@ +package api_test + +import ( + "context" + "net/http" + "regexp" + "strings" + "testing" + "time" + + "github.com/jackc/pgx/v5" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/config" + "git.zb-server.de/ZB-Server/uptimesebi/internal/notify/notifytest" +) + +var verifyLink = regexp.MustCompile(`/verify\?token=([A-Za-z0-9_\-]+)`) + +func TestVerifiedSignup(t *testing.T) { + mail := notifytest.NewSMTP(t) + e := newEnvWith(t, func(c *config.API) { + c.SMTPURL, c.SignupVerify, c.SignupsPerIP = mail.URL(), "auto", 2 + }) + // mailFor waits for the n-th mail and returns its confirmation token. + tokenOf := func(n int, to string) string { + t.Helper() + waitFor(t, 5*time.Second, "the confirmation mail", func() bool { return len(mail.Messages()) >= n }) + msg := mail.Messages()[n-1] + if !strings.Contains(strings.Join(msg.To, ","), to) { + t.Fatalf("mail %d went to %v, want %s", n, msg.To, to) + } + m := verifyLink.FindStringSubmatch(msg.Data) + if m == nil { + t.Fatalf("mail lacks the link: %s", msg.Data) + } + return m[1] + } + box := uniq("max.power") + email := strings.ToUpper(box[:1]) + box[1:] + "+uptime@googlemail.com" + lower := strings.ToLower(email) + + // Signing up mails a link instead of signing in. + b := e.browser(t) + st, body := b.do("POST", "/api/v1/auth/signup", map[string]any{"email": email, "password": testPassword, "display_name": "Max"}) + if st != http.StatusOK || body["status"] != "verification_sent" { + t.Fatalf("signup = %d %v", st, body) + } + if st, _ := b.do("GET", "/api/v1/me", nil); st != http.StatusUnauthorized { + t.Errorf("signed in before confirming: %d", st) + } + token := tokenOf(1, lower) + + // Unconfirmed accounts cannot sign in; only the right password says why. + st, body = e.browser(t).do("POST", "/api/v1/auth/login", map[string]any{"email": email, "password": testPassword}) + expect(t, "sign-in before confirming", st, body, http.StatusForbidden, "email_unverified") + if st, _ := e.browser(t).do("POST", "/api/v1/auth/login", map[string]any{"email": email, "password": "wrong password"}); st != http.StatusUnauthorized { + t.Error("a wrong password reveals the missing confirmation") + } + + // The same mailbox under another address is refused. + st, body = e.browser(t).do("POST", "/api/v1/auth/signup", map[string]any{"email": strings.ReplaceAll(box, ".", "") + "@gmail.com", "password": testPassword}) + expect(t, "alias of an existing account", st, body, http.StatusConflict, "email_taken") + + // Resending answers alike for unknown addresses and mails only real ones. + if st, _ := e.browser(t).do("POST", "/api/v1/auth/verify/resend", map[string]any{"email": "nobody@" + uniq("x") + ".test"}); st != http.StatusNoContent { + t.Errorf("resend for unknown = %d", st) + } + if st, _ := e.browser(t).do("POST", "/api/v1/auth/verify/resend", map[string]any{"email": email}); st != http.StatusNoContent { + t.Errorf("resend = %d", st) + } + tokenOf(2, lower) + if n := len(mail.Messages()); n != 2 { + t.Errorf("%d mails, want 2", n) + } + + // The link page asks before confirming; confirming signs in once. + if _, _, html := b.page("/verify?token=" + token); !strings.Contains(html, `name="token"`) { + t.Error("the link page lacks its form") + } + if st, body := b.do("POST", "/api/v1/auth/verify", map[string]any{"token": token}); st != http.StatusOK { + t.Fatalf("verify = %d %v", st, body) + } + st, body = e.browser(t).do("POST", "/api/v1/auth/verify", map[string]any{"token": token}) + expect(t, "token used twice", st, body, http.StatusGone, "verification_expired") + + // Without an organization, the console asks for one. + if got := b.visit("/"); got.Path != "/orgs/new" { + t.Errorf("dashboard leads to %s, want /orgs/new", got.Path) + } + slug := uniq("max-") + if st, body := b.do("POST", "/api/v1/orgs", map[string]any{"name": "Max Corp", "slug": slug}); st != http.StatusCreated { + t.Fatalf("create org = %d %v", st, body) + } + if got := b.visit("/"); got.Path != "/" { + t.Errorf("dashboard leads to %s after creating an organization", got.Path) + } + _, me := b.do("GET", "/api/v1/me", nil) + if !strings.Contains(mustJSON(me), slug) { + t.Errorf("me lacks the new organization: %v", me) + } + + // The account limit on organizations. + _ = e.asSystem(t, func(tx pgx.Tx) error { + _, err := tx.Exec(context.Background(), `UPDATE users SET limit_orgs = 1 WHERE email = $1`, lower) + return err + }) + st, body = b.do("POST", "/api/v1/orgs", map[string]any{"name": "Second", "slug": uniq("max2-")}) + expect(t, "second organization", st, body, http.StatusUnprocessableEntity, "org_limit") + + // Two accounts per client address and day; refused sign-ups do not count. + if st, body := e.browser(t).do("POST", "/api/v1/auth/signup", map[string]any{"email": "two@" + uniq("x") + ".test", "password": testPassword}); st != http.StatusOK { + t.Fatalf("second account = %d %v", st, body) + } + st, body = e.browser(t).do("POST", "/api/v1/auth/signup", map[string]any{"email": "three@" + uniq("x") + ".test", "password": testPassword}) + expect(t, "third account", st, body, http.StatusTooManyRequests, "signup_limit") + + // Unconfirmed accounts go after a week. + _ = e.asSystem(t, func(tx pgx.Tx) error { + _, err := tx.Exec(context.Background(), `UPDATE users SET created_at = now() - interval '8 days' WHERE email_verified_at IS NULL AND email LIKE 'two@%'`) + return err + }) + if err := e.api.Housekeep(context.Background(), time.Now()); err != nil { + t.Fatal(err) + } + var left int + _ = e.asSystem(t, func(tx pgx.Tx) error { + return tx.QueryRow(context.Background(), `SELECT count(*) FROM users WHERE email LIKE 'two@%' AND created_at < now() - interval '7 days'`).Scan(&left) + }) + if left != 0 { + t.Error("an unconfirmed account outlived its week") + } +} + +func TestSignupNeedsMail(t *testing.T) { + e := newEnvWith(t, func(c *config.API) { c.SignupVerify = "required" }) + st, body := e.browser(t).do("POST", "/api/v1/auth/signup", map[string]any{"email": "a@" + uniq("x") + ".test", "password": testPassword}) + expect(t, "sign-up without a mail server", st, body, http.StatusForbidden, "signup_closed") +} diff --git a/internal/api/sso.go b/internal/api/sso.go index 115d185..7371ecb 100644 --- a/internal/api/sso.go +++ b/internal/api/sso.go @@ -319,10 +319,17 @@ func (s *Server) ssoResolveUser(ctx context.Context, row store.SsoProvider, cl s } else if !errors.Is(err, pgx.ErrNoRows) { return err } + // Another address of the same mailbox has an account. + if taken, err := q.EmailKeyTaken(ctx, ptr(emailKey(email))); err != nil || taken { + code = "sso_link_required" + return err + } + // The identity provider confirmed the address. u, err := q.CreateUser(ctx, store.CreateUserParams{ Email: email, DisplayName: truncate(strings.TrimSpace(cl.Name), 200), Locale: ptr(i18n.Lang(ctx)), + EmailKey: ptr(emailKey(email)), EmailVerifiedAt: ptr(time.Now()), }) if err != nil { return err diff --git a/internal/config/config.go b/internal/config/config.go index 3e42559..77570d5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -74,9 +74,16 @@ const ( type API struct { Common Storage - Listen string `env:"UPTIME_API_LISTEN" envDefault:":8080"` - SecretKeys string `env:"UPTIME_SECRET_KEYS"` - Signup SignupMode `env:"UPTIME_SIGNUP" envDefault:"first-user"` + Listen string `env:"UPTIME_API_LISTEN" envDefault:":8080"` + SecretKeys string `env:"UPTIME_SECRET_KEYS"` + Signup SignupMode `env:"UPTIME_SIGNUP" envDefault:"first-user"` + // SignupVerify is "auto", "required" or "off": whether new accounts + // confirm their email address before signing in. Auto requires it in + // the cloud edition and wherever mail can be sent. + SignupVerify string `env:"UPTIME_SIGNUP_VERIFY" envDefault:"auto"` + // SignupsPerIP limits sign-ups per client address (IPv6: per /64) in + // 24 hours; 0 means unlimited. + SignupsPerIP int `env:"UPTIME_SIGNUPS_PER_IP" envDefault:"2"` SessionIdle time.Duration `env:"UPTIME_SESSION_IDLE" envDefault:"168h"` SessionAbsolute time.Duration `env:"UPTIME_SESSION_ABSOLUTE" envDefault:"720h"` // PublicURL is the externally reachable base URL, used for SSO callbacks. @@ -137,6 +144,18 @@ func (a API) Validate() error { default: return fmt.Errorf("config: unknown UPTIME_SIGNUP %q", a.Signup) } + switch a.SignupVerify { + case "auto", "required": + case "off": + if a.Edition == EditionCloud { + return fmt.Errorf("config: UPTIME_SIGNUP_VERIFY=off is not allowed in the cloud edition") + } + default: + return fmt.Errorf("config: UPTIME_SIGNUP_VERIFY must be auto, required or off") + } + if a.SignupsPerIP < 0 { + return fmt.Errorf("config: UPTIME_SIGNUPS_PER_IP must not be negative") + } switch a.SSOPrivateNetworks { case "auto", "true", "false": default: diff --git a/internal/i18n/locales/de.json b/internal/i18n/locales/de.json index edff6e5..2bcd14f 100644 --- a/internal/i18n/locales/de.json +++ b/internal/i18n/locales/de.json @@ -56,6 +56,7 @@ "audit.action.account.signup": "Konto erstellt", "audit.action.account.totp_disable": "Zwei-Faktor-Authentifizierung deaktiviert", "audit.action.account.totp_enable": "Zwei-Faktor-Authentifizierung aktiviert", + "audit.action.account.verify": "E-Mail-Adresse bestätigt", "audit.action.agent.create": "Agent erstellt", "audit.action.agent.delete": "Agent widerrufen", "audit.action.agent.update": "Agent geändert", @@ -88,6 +89,7 @@ "audit.action.monitor.delete": "Monitor gelöscht", "audit.action.monitor.update": "Monitor geändert", "audit.action.org.check_types_update": "Check-Typen geändert", + "audit.action.org.create": "Organisation angelegt", "audit.action.org.delete": "Organisation gelöscht", "audit.action.org.export": "Daten der Organisation exportiert", "audit.action.org.legal_update": "Rechtstext geändert", @@ -153,6 +155,16 @@ "auth.sso.heading": "Single Sign-on", "auth.sso.org_placeholder": "Kurzname der Organisation", "auth.sso.submit": "Weiter", + "auth.verify.intro": "Drücke den Knopf, um deine E-Mail-Adresse zu bestätigen und dich anzumelden.", + "auth.verify.resend_intro": "Wenn ein unbestätigtes Konto diese Adresse nutzt, schicken wir ihm einen neuen Link.", + "auth.verify.resend_link": "Bestätigungs-E-Mail erneut senden", + "auth.verify.resend_submit": "Link senden", + "auth.verify.resend_title": "Neuer Bestätigungslink", + "auth.verify.sent": "Wir haben dir einen Link geschickt, mit dem du deine E-Mail-Adresse bestätigst. Er ist 24 Stunden gültig.", + "auth.verify.sent_hint": "Nichts angekommen? Schau im Spam-Ordner nach oder fordere einen neuen Link an.", + "auth.verify.sent_title": "Schau in dein Postfach", + "auth.verify.submit": "Bestätigen und anmelden", + "auth.verify.title": "E-Mail-Adresse bestätigen", "channels.create": "Kanal anlegen", "channels.created": "Webhook erstellt. Er ist bereits in der Standardgruppe. Kopiere den Signaturschlüssel, bevor du fortfährst.", "channels.delete_confirm": "Diesen Kanal löschen?", @@ -466,6 +478,8 @@ "email.resolved.subject": "[UP] {{.Monitor}}", "email.test.body": "Dies ist ein Test. Wenn du ihn lesen kannst, funktioniert der Kanal.", "email.test.subject": "Testbenachrichtigung von UptimeSebi", + "email.verify.body": "Hallo,\n\nbitte bestätige deine E-Mail-Adresse, um die Registrierung abzuschließen:\n\n{{.Link}}\n\nDer Link ist {{.Hours}} Stunden gültig. Wenn du dich nicht registriert hast, ignoriere diese E-Mail; das Konto wird nach einer Woche gelöscht.", + "email.verify.subject": "Bestätige deine E-Mail-Adresse für UptimeSebi", "error.account_suspended": "Dieser Account ist gesperrt. Wende dich an den Betreiber.", "error.agent_protocol_unsupported": "Diese Agent-Version wird von der API nicht unterstützt. Bitte den Agent aktualisieren.", "error.alert_group_not_deletable": "Die Gruppe existiert nicht oder ist die geschützte Standardgruppe.", @@ -480,6 +494,7 @@ "error.domain_taken": "Diese Domain nutzt bereits eine andere Statuspage.", "error.email_not_configured": "E-Mail ist auf diesem Server nicht verfügbar.", "error.email_taken": "Diese E-Mail-Adresse ist bereits registriert.", + "error.email_unverified": "Bestätige zuerst deine E-Mail-Adresse; wir haben dir einen Link geschickt. Einen neuen kannst du unten anfordern.", "error.forbidden": "Dafür fehlt dir die Berechtigung.", "error.group_cycle": "Eine Gruppe kann nicht in sich selbst oder eine ihrer Untergruppen verschoben werden.", "error.group_too_deep": "Gruppen lassen sich höchstens acht Ebenen tief verschachteln.", @@ -537,6 +552,7 @@ "error.no_domain": "Lege zuerst eine eigene Domain fest.", "error.no_password": "Konto ohne Passwort.", "error.not_found": "Nicht gefunden.", + "error.org_limit": "Dein Konto darf höchstens {{.Max}} Organisationen besitzen.", "error.org_not_found": "Organisation nicht gefunden.", "error.org_suspended": "Der Betreiber hat diese Organisation gesperrt.", "error.owner_cannot_be_removed": "Der Owner kann nicht entfernt werden.", @@ -556,6 +572,7 @@ "error.role_not_found": "Rolle nicht gefunden.", "error.session_required": "Diese Aktion ist für API-Tokens nicht verfügbar.", "error.signup_closed": "Registrierung ist deaktiviert.", + "error.signup_limit": "Aus deinem Netz wurden heute zu viele Konten angelegt. Versuche es morgen wieder.", "error.slug_taken": "Dieser Kurzname ist bereits vergeben.", "error.sso_denied": "Die Anmeldung wurde beim Identity Provider abgebrochen.", "error.sso_discovery_failed": "Der Identity Provider ist nicht erreichbar oder lieferte keine gültige Konfiguration.", @@ -582,6 +599,8 @@ "error.unauthenticated": "Anmeldung erforderlich.", "error.unsupported_locale": "Sprache wird nicht unterstützt.", "error.user_owns_shared_orgs": "Dem Account gehören Organisationen mit weiteren Mitgliedern. Lösche diese zuerst oder übertrage sie.", + "error.verification_expired": "Dieser Bestätigungslink ist ungültig oder abgelaufen. Fordere einen neuen an.", + "error.verification_mail_failed": "Dein Konto wurde angelegt, aber die Bestätigungs-E-Mail konnte nicht gesendet werden. Fordere später einen neuen Link an.", "evidence.body": "Antwort-Body", "evidence.body_binary": "Binärer Inhalt, nicht gespeichert.", "evidence.body_empty": "Leer.", @@ -1043,9 +1062,14 @@ "org.token_max_days": "Maximale Gültigkeit von API-Tokens (Tage)", "org.token_max_days_hint": "Neue Tokens müssen innerhalb dieses Zeitraums ablaufen. Beim Speichern werden bestehende Tokens gekürzt, die länger gelten würden. Leer lassen für keine Begrenzung.", "org.token_max_days_none": "unbegrenzt", + "orgs.create": "Organisation anlegen", + "orgs.first_intro": "Dein Konto ist eingerichtet. Lege eine Organisation für deine Monitore und Statusseiten an.", "orgs.intro": "Alle Organisationen mit Inhaber, Nutzung und Limits. Ein leeres Limit folgt dem Standard.", + "orgs.invited_hint": "Wurdest du in eine Organisation eingeladen? Öffne stattdessen den Link aus der Einladung.", "orgs.limits": "Limits dieser Organisation", "orgs.manage": "Limits, sperren oder löschen …", + "orgs.new_intro": "Du bist Inhaber und kannst andere einladen.", + "orgs.new_title": "Neue Organisation", "orgs.none": "Keine Organisation gefunden.", "orgs.owner_orgs": "Organisationen, die der Inhaber besitzen darf (besitzt {{.Count}})", "orgs.search": "Name, Kürzel oder E-Mail des Inhabers", diff --git a/internal/i18n/locales/en.json b/internal/i18n/locales/en.json index d426b83..5ac35ea 100644 --- a/internal/i18n/locales/en.json +++ b/internal/i18n/locales/en.json @@ -56,6 +56,7 @@ "audit.action.account.signup": "Account created", "audit.action.account.totp_disable": "Two-factor authentication disabled", "audit.action.account.totp_enable": "Two-factor authentication enabled", + "audit.action.account.verify": "Email address confirmed", "audit.action.agent.create": "Agent created", "audit.action.agent.delete": "Agent revoked", "audit.action.agent.update": "Agent changed", @@ -88,6 +89,7 @@ "audit.action.monitor.delete": "Monitor deleted", "audit.action.monitor.update": "Monitor changed", "audit.action.org.check_types_update": "Check types changed", + "audit.action.org.create": "Organization created", "audit.action.org.delete": "Organization deleted", "audit.action.org.export": "Organization data exported", "audit.action.org.legal_update": "Legal document changed", @@ -153,6 +155,16 @@ "auth.sso.heading": "Single sign-on", "auth.sso.org_placeholder": "Organization short name", "auth.sso.submit": "Continue", + "auth.verify.intro": "Press the button to confirm your email address and sign in.", + "auth.verify.resend_intro": "If an unconfirmed account uses this address, we send it a new link.", + "auth.verify.resend_link": "Resend the confirmation email", + "auth.verify.resend_submit": "Send link", + "auth.verify.resend_title": "New confirmation link", + "auth.verify.sent": "We sent you a link to confirm your email address. It is valid for 24 hours.", + "auth.verify.sent_hint": "Nothing arrived? Look in your spam folder, or ask for a new link.", + "auth.verify.sent_title": "Check your inbox", + "auth.verify.submit": "Confirm and sign in", + "auth.verify.title": "Confirm your email address", "channels.create": "Create channel", "channels.created": "Webhook created. It is already in the default alert group. Copy the signing secret before continuing.", "channels.delete_confirm": "Delete this channel?", @@ -466,6 +478,8 @@ "email.resolved.subject": "[UP] {{.Monitor}}", "email.test.body": "This is a test. If you can read it, the channel works.", "email.test.subject": "Test notification from UptimeSebi", + "email.verify.body": "Hello,\n\nplease confirm your email address to finish signing up:\n\n{{.Link}}\n\nThe link is valid for {{.Hours}} hours. If you did not sign up, ignore this email; the account is deleted after a week.", + "email.verify.subject": "Confirm your email address for UptimeSebi", "error.account_suspended": "This account is suspended. Contact the operator.", "error.agent_protocol_unsupported": "This agent version is not supported by the API. Please update the agent.", "error.alert_group_not_deletable": "The group does not exist or is the protected default group.", @@ -480,6 +494,7 @@ "error.domain_taken": "This domain is already used by another status page.", "error.email_not_configured": "Email is not available on this server.", "error.email_taken": "This email address is already registered.", + "error.email_unverified": "Confirm your email address first; we mailed you a link. You can ask for a new one below.", "error.forbidden": "You are not allowed to do this.", "error.group_cycle": "A group cannot be placed inside itself or one of its subgroups.", "error.group_too_deep": "Groups can be nested at most eight levels deep.", @@ -537,6 +552,7 @@ "error.no_domain": "Set a custom domain first.", "error.no_password": "This account has no password.", "error.not_found": "Not found.", + "error.org_limit": "Your account may own at most {{.Max}} organizations.", "error.org_not_found": "Organization not found.", "error.org_suspended": "The operator suspended this organization.", "error.owner_cannot_be_removed": "The owner cannot be removed.", @@ -556,6 +572,7 @@ "error.role_not_found": "Role not found.", "error.session_required": "This action is not available to API tokens.", "error.signup_closed": "Sign-up is disabled.", + "error.signup_limit": "Too many accounts were created from your network today. Try again tomorrow.", "error.slug_taken": "This short name is already taken.", "error.sso_denied": "Sign-in was cancelled at the identity provider.", "error.sso_discovery_failed": "The identity provider could not be reached or returned no valid configuration.", @@ -582,6 +599,8 @@ "error.unauthenticated": "Authentication required.", "error.unsupported_locale": "Unsupported language.", "error.user_owns_shared_orgs": "The account owns organizations with other members. Delete those or hand them over first.", + "error.verification_expired": "This confirmation link is invalid or expired. Ask for a new one.", + "error.verification_mail_failed": "Your account was created, but the confirmation email could not be sent. Ask for a new link in a while.", "evidence.body": "Response body", "evidence.body_binary": "Binary content, not stored.", "evidence.body_empty": "Empty.", @@ -1043,9 +1062,14 @@ "org.token_max_days": "Maximum API token lifetime (days)", "org.token_max_days_hint": "New tokens must expire within this period. Saving shortens existing tokens that would outlive it. Leave empty for no limit.", "org.token_max_days_none": "unlimited", + "orgs.create": "Create organization", + "orgs.first_intro": "Your account is ready. Create an organization for your monitors and status pages.", "orgs.intro": "All organizations with their owner, usage and limits. Leave a limit empty to follow the default.", + "orgs.invited_hint": "Were you invited to an organization? Open the link from the invitation instead.", "orgs.limits": "Limits of this organization", "orgs.manage": "Limits, suspend or delete …", + "orgs.new_intro": "You will own it and can invite others.", + "orgs.new_title": "New organization", "orgs.none": "No organization matches.", "orgs.owner_orgs": "Organizations the owner may own (owns {{.Count}})", "orgs.search": "Name, slug or owner email", diff --git a/internal/migrations/sql/00044_email_verification.sql b/internal/migrations/sql/00044_email_verification.sql new file mode 100644 index 0000000..5d16f0c --- /dev/null +++ b/internal/migrations/sql/00044_email_verification.sql @@ -0,0 +1,32 @@ +-- +goose Up +-- Accounts confirm their email address before signing in; existing ones +-- count as confirmed. +ALTER TABLE users ADD COLUMN email_verified_at timestamptz; +UPDATE users SET email_verified_at = created_at; + +-- One account per mailbox: email_key is the address with +suffixes and, +-- for Gmail, dots removed (see emailKey in the api package). Accounts that +-- already share a key keep theirs empty; only the oldest holds it. +ALTER TABLE users ADD COLUMN email_key text; +WITH parts AS ( + SELECT id, created_at, + split_part(split_part(lower(email::text), '@', 1), '+', 1) AS local, + split_part(lower(email::text), '@', 2) AS domain + FROM users +), keyed AS ( + SELECT id, + CASE WHEN domain IN ('gmail.com', 'googlemail.com') THEN replace(local, '.', '') || '@gmail.com' + ELSE local || '@' || domain END AS key, + row_number() OVER (PARTITION BY + CASE WHEN domain IN ('gmail.com', 'googlemail.com') THEN replace(local, '.', '') || '@gmail.com' + ELSE local || '@' || domain END + ORDER BY created_at) AS n + FROM parts +) +UPDATE users u SET email_key = keyed.key FROM keyed WHERE keyed.id = u.id AND keyed.n = 1; +CREATE UNIQUE INDEX users_email_key_idx ON users (email_key); + +-- +goose Down +DROP INDEX users_email_key_idx; +ALTER TABLE users DROP COLUMN email_key; +ALTER TABLE users DROP COLUMN email_verified_at; diff --git a/internal/store/models.go b/internal/store/models.go index 29fa41c..b8d697c 100644 --- a/internal/store/models.go +++ b/internal/store/models.go @@ -389,19 +389,21 @@ type StatusPageMonitor struct { } type User struct { - ID uuid.UUID - Email string - DisplayName string - PasswordHash *string - DisabledAt *time.Time - CreatedAt time.Time - UpdatedAt time.Time - TotpSecret []byte - TotpEnabledAt *time.Time - Locale *string - IsAdmin bool - DisabledReason string - LimitOrgs *int32 + ID uuid.UUID + Email string + DisplayName string + PasswordHash *string + DisabledAt *time.Time + CreatedAt time.Time + UpdatedAt time.Time + TotpSecret []byte + TotpEnabledAt *time.Time + Locale *string + IsAdmin bool + DisabledReason string + LimitOrgs *int32 + EmailVerifiedAt *time.Time + EmailKey *string } type UserIdentity struct { diff --git a/internal/store/querier.go b/internal/store/querier.go index 5bf9de8..03da4b0 100644 --- a/internal/store/querier.go +++ b/internal/store/querier.go @@ -47,6 +47,7 @@ type Querier interface { ClearStatusPageGroups(ctx context.Context, pageID uuid.UUID) error ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID) error CountMonitors(ctx context.Context, orgID uuid.UUID) (int64, error) + CountOwnedOrgs(ctx context.Context, userID uuid.UUID) (int64, error) CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error) CountStatusPages(ctx context.Context, orgID uuid.UUID) (int64, error) CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error) @@ -99,6 +100,7 @@ type Querier interface { DeleteSuccessEvidence(ctx context.Context, arg DeleteSuccessEvidenceParams) error DeleteUser(ctx context.Context, id uuid.UUID) (int64, error) DisableTOTP(ctx context.Context, id uuid.UUID) error + EmailKeyTaken(ctx context.Context, emailKey *string) (bool, error) EnableTOTP(ctx context.Context, arg EnableTOTPParams) error EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error // An empty name names a new region after its key and keeps an existing name. @@ -224,6 +226,7 @@ type Querier interface { MaintenanceForMonitors(ctx context.Context, ids []uuid.UUID) ([]MaintenanceForMonitorsRow, error) MakeAdmin(ctx context.Context, id uuid.UUID) error MarkDomainVerified(ctx context.Context, id uuid.UUID) error + MarkEmailVerified(ctx context.Context, id uuid.UUID) (User, error) MarkInvitationAccepted(ctx context.Context, id uuid.UUID) (int64, error) MarkNotificationFailed(ctx context.Context, arg MarkNotificationFailedParams) error MarkNotificationSent(ctx context.Context, id uuid.UUID) error @@ -262,6 +265,8 @@ type Querier interface { // Delivered and given-up notifications; pending ones are still being worked. PurgeNotifications(ctx context.Context, createdAt time.Time) (int64, error) PurgeOrgCheckData(ctx context.Context, org uuid.UUID) error + // Accounts never confirmed; they belong to no organization. + PurgeUnverifiedUsers(ctx context.Context, createdAt time.Time) (int64, error) // Raw results bucketed by width since a point in time, for short ranges. RangeBuckets(ctx context.Context, arg RangeBucketsParams) ([]RangeBucketsRow, error) // The daily aggregate rebucketed by width, for ranges of months. diff --git a/internal/store/queries/users.sql b/internal/store/queries/users.sql index 824f1be..a7f4e84 100644 --- a/internal/store/queries/users.sql +++ b/internal/store/queries/users.sql @@ -1,7 +1,21 @@ -- name: CreateUser :one -INSERT INTO users (email, display_name, password_hash, locale) VALUES ($1, $2, $3, $4) +INSERT INTO users (email, display_name, password_hash, locale, email_key, email_verified_at) +VALUES ($1, $2, $3, $4, sqlc.arg(email_key), sqlc.narg(email_verified_at)) RETURNING *; +-- name: MarkEmailVerified :one +UPDATE users SET email_verified_at = coalesce(email_verified_at, now()) WHERE id = $1 +RETURNING *; + +-- name: PurgeUnverifiedUsers :execrows +-- Accounts never confirmed; they belong to no organization. +DELETE FROM users u +WHERE u.email_verified_at IS NULL AND u.created_at < $1 + AND NOT EXISTS (SELECT 1 FROM memberships m WHERE m.user_id = u.id); + +-- name: CountOwnedOrgs :one +SELECT count(*) FROM memberships WHERE user_id = $1 AND is_owner; + -- name: GetUser :one SELECT * FROM users WHERE id = $1; @@ -31,3 +45,6 @@ UPDATE users SET is_admin = $2, updated_at = now() WHERE email = $1; -- name: MakeAdmin :exec UPDATE users SET is_admin = true, updated_at = now() WHERE id = $1; + +-- name: EmailKeyTaken :one +SELECT EXISTS (SELECT 1 FROM users WHERE email_key = $1); diff --git a/internal/store/users.sql.go b/internal/store/users.sql.go index c01aa50..82a098f 100644 --- a/internal/store/users.sql.go +++ b/internal/store/users.sql.go @@ -7,6 +7,7 @@ package store import ( "context" + "time" "github.com/google/uuid" ) @@ -22,16 +23,30 @@ func (q *Queries) AnyUserExists(ctx context.Context) (bool, error) { return exists, err } +const countOwnedOrgs = `-- name: CountOwnedOrgs :one +SELECT count(*) FROM memberships WHERE user_id = $1 AND is_owner +` + +func (q *Queries) CountOwnedOrgs(ctx context.Context, userID uuid.UUID) (int64, error) { + row := q.db.QueryRow(ctx, countOwnedOrgs, userID) + var count int64 + err := row.Scan(&count) + return count, err +} + const createUser = `-- name: CreateUser :one -INSERT INTO users (email, display_name, password_hash, locale) VALUES ($1, $2, $3, $4) -RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason, limit_orgs +INSERT INTO users (email, display_name, password_hash, locale, email_key, email_verified_at) +VALUES ($1, $2, $3, $4, $5, $6) +RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason, limit_orgs, email_verified_at, email_key ` type CreateUserParams struct { - Email string - DisplayName string - PasswordHash *string - Locale *string + Email string + DisplayName string + PasswordHash *string + Locale *string + EmailKey *string + EmailVerifiedAt *time.Time } func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) { @@ -40,6 +55,8 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e arg.DisplayName, arg.PasswordHash, arg.Locale, + arg.EmailKey, + arg.EmailVerifiedAt, ) var i User err := row.Scan( @@ -56,6 +73,8 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e &i.IsAdmin, &i.DisabledReason, &i.LimitOrgs, + &i.EmailVerifiedAt, + &i.EmailKey, ) return i, err } @@ -81,6 +100,17 @@ func (q *Queries) DisableTOTP(ctx context.Context, id uuid.UUID) error { return err } +const emailKeyTaken = `-- name: EmailKeyTaken :one +SELECT EXISTS (SELECT 1 FROM users WHERE email_key = $1) +` + +func (q *Queries) EmailKeyTaken(ctx context.Context, emailKey *string) (bool, error) { + row := q.db.QueryRow(ctx, emailKeyTaken, emailKey) + var exists bool + err := row.Scan(&exists) + return exists, err +} + const enableTOTP = `-- name: EnableTOTP :exec UPDATE users SET totp_secret = $2, totp_enabled_at = now(), updated_at = now() WHERE id = $1 ` @@ -96,7 +126,7 @@ func (q *Queries) EnableTOTP(ctx context.Context, arg EnableTOTPParams) error { } const getUser = `-- name: GetUser :one -SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason, limit_orgs FROM users WHERE id = $1 +SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason, limit_orgs, email_verified_at, email_key FROM users WHERE id = $1 ` func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) { @@ -116,12 +146,14 @@ func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) { &i.IsAdmin, &i.DisabledReason, &i.LimitOrgs, + &i.EmailVerifiedAt, + &i.EmailKey, ) return i, err } const getUserByEmail = `-- name: GetUserByEmail :one -SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason, limit_orgs FROM users WHERE email = $1 +SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason, limit_orgs, email_verified_at, email_key FROM users WHERE email = $1 ` func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) { @@ -141,6 +173,8 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error &i.IsAdmin, &i.DisabledReason, &i.LimitOrgs, + &i.EmailVerifiedAt, + &i.EmailKey, ) return i, err } @@ -154,6 +188,49 @@ func (q *Queries) MakeAdmin(ctx context.Context, id uuid.UUID) error { return err } +const markEmailVerified = `-- name: MarkEmailVerified :one +UPDATE users SET email_verified_at = coalesce(email_verified_at, now()) WHERE id = $1 +RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason, limit_orgs, email_verified_at, email_key +` + +func (q *Queries) MarkEmailVerified(ctx context.Context, id uuid.UUID) (User, error) { + row := q.db.QueryRow(ctx, markEmailVerified, id) + var i User + err := row.Scan( + &i.ID, + &i.Email, + &i.DisplayName, + &i.PasswordHash, + &i.DisabledAt, + &i.CreatedAt, + &i.UpdatedAt, + &i.TotpSecret, + &i.TotpEnabledAt, + &i.Locale, + &i.IsAdmin, + &i.DisabledReason, + &i.LimitOrgs, + &i.EmailVerifiedAt, + &i.EmailKey, + ) + return i, err +} + +const purgeUnverifiedUsers = `-- name: PurgeUnverifiedUsers :execrows +DELETE FROM users u +WHERE u.email_verified_at IS NULL AND u.created_at < $1 + AND NOT EXISTS (SELECT 1 FROM memberships m WHERE m.user_id = u.id) +` + +// Accounts never confirmed; they belong to no organization. +func (q *Queries) PurgeUnverifiedUsers(ctx context.Context, createdAt time.Time) (int64, error) { + result, err := q.db.Exec(ctx, purgeUnverifiedUsers, createdAt) + if err != nil { + return 0, err + } + return result.RowsAffected(), nil +} + const setPasswordHash = `-- name: SetPasswordHash :exec UPDATE users SET password_hash = $2, updated_at = now() WHERE id = $1 ` diff --git a/internal/web/assets/app.js b/internal/web/assets/app.js index 73aeff9..3a6310e 100644 --- a/internal/web/assets/app.js +++ b/internal/web/assets/app.js @@ -140,6 +140,9 @@ } let next = form.dataset.next || location.href; if (form.dataset.nextFrom) next += res.data?.[form.dataset.nextFrom] ?? ""; + // The server may name where to go, within this site. + const redirect = res.data?.redirect; + if (typeof redirect === "string" && redirect.startsWith("/") && !redirect.startsWith("//")) next = redirect; location.assign(next); } catch (err) { showError(form, message(err)); diff --git a/internal/web/auth.templ b/internal/web/auth.templ index fbf5b84..a81be86 100644 --- a/internal/web/auth.templ +++ b/internal/web/auth.templ @@ -19,6 +19,7 @@ templ Login(p Page, signupAllowed bool, next string) { @submit(i18n.T(ctx, "auth.login.submit")) +

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

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

@@ -49,11 +50,75 @@ templ Signup(p Page) { @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) -
- @field(i18n.T(ctx, "auth.field.org_name"), "org_name", "text", "organization", true) - @field(i18n.T(ctx, "auth.field.org_slug"), "org_slug", "text", "off", true) @submit(i18n.T(ctx, "auth.signup.submit"))

{ 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() +
+ } + } +} diff --git a/internal/web/auth_templ.go b/internal/web/auth_templ.go index adfc79f..88f8b60 100644 --- a/internal/web/auth_templ.go +++ b/internal/web/auth_templ.go @@ -105,90 +105,103 @@ func Login(p Page, signupAllowed bool, next string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var5 string - templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.sso.heading")) + templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.verify.resend_link")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 23, Col: 108} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 22, Col: 154} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var6 string - templ_7745c5c3_Var6, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "auth.sso.org_placeholder")).Resolve(ctx) + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.sso.heading")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 28, Col: 58} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 24, Col: 108} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" aria-label=\"") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "\" autocomplete=\"organization\" required>
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if signupAllowed { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var9 string - templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.no_account")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 38, Col: 42} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var10 string - templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.to_signup")) + templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.no_account")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 39, Col: 105} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 39, Col: 42} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var11 string + templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.to_signup")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 40, Col: 105} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -220,7 +233,7 @@ func Signup(p Page) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var12 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var13 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { @@ -232,7 +245,7 @@ func Signup(p Page) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -252,18 +265,6 @@ func Signup(p Page) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.org_name"), "org_name", "text", "organization", true).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.org_slug"), "org_slug", "text", "off", true).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } templ_7745c5c3_Err = submit(i18n.T(ctx, "auth.signup.submit")).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -272,12 +273,12 @@ func Signup(p Page) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var13 string - templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.signup.to_login")) + var templ_7745c5c3_Var14 string + templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.signup.to_login")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 57, Col: 137} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 55, Col: 137} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -287,7 +288,7 @@ func Signup(p Page) templ.Component { } return nil }) - templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var12), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var13), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -295,4 +296,481 @@ func Signup(p Page) templ.Component { }) } +func SignupSent(p Page) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var16 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var17 string + templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.verify.sent")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 61, Col: 54} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var18 string + templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.verify.sent_hint")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 62, Col: 75} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var19 string + templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.verify.resend_link")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 63, Col: 128} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var16), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// Verify confirms an address when the visitor presses the button. +func Verify(p Page, token string) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var21 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + if token == "" { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var22 string + templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "error.verification_expired")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 71, Col: 65} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var23 string + templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.verify.resend_link")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 72, Col: 129} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var25 string + templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.verify.intro")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 77, Col: 62} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = submit(i18n.T(ctx, "auth.verify.submit")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var26 string + templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.verify.resend_link")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 80, Col: 155} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) + templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var21), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func ResendVerification(p Page) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var28 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var29 string + templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.verify.resend_intro")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 89, Col: 79} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = submit(i18n.T(ctx, "auth.verify.resend_submit")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var30 string + templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.signup.to_login")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 93, Col: 137} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var28), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func newOrgForm() templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.org_name"), "name", "text", "organization", true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.org_slug"), "slug", "text", "off", true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = submit(i18n.T(ctx, "orgs.create")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// NewOrgPage creates an organization: the first, in a page of its own +// since there is no console yet, or another one. +func NewOrgPage(p Page, me Me) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + if len(me.Orgs) == 0 { + templ_7745c5c3_Var33 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var34 string + templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.first_intro")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 111, Col: 71} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = newOrgForm().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var35 string + templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.invited_hint")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 113, Col: 72} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var33), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Var37 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = settingsHeading("orgs.new_title", "orgs.new_intro").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = newOrgForm().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var37), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) +} + var _ = templruntime.GeneratedTemplate diff --git a/internal/web/console.templ b/internal/web/console.templ index d1c3e55..0d68194 100644 --- a/internal/web/console.templ +++ b/internal/web/console.templ @@ -51,6 +51,7 @@ templ consoleShell(p Page, me Me) { } else if len(me.Orgs) == 1 { { me.Orgs[0].Name } } + +
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if me.OrgSuspended { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var13 string - templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.org_suspended")) + var templ_7745c5c3_Var15 string + templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.org_suspended")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 77, Col: 51} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 78, Col: 51} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, " ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if me.SuspendedReason != "" { - var templ_7745c5c3_Var14 string - templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(" " + i18n.T(ctx, "console.suspended_reason", "Reason", me.SuspendedReason)) + var templ_7745c5c3_Var16 string + templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(" " + i18n.T(ctx, "console.suspended_reason", "Reason", me.SuspendedReason)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 79, Col: 83} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 80, Col: 83} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, " ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -333,7 +359,7 @@ func consoleShell(p Page, me Me) templ.Component { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -345,7 +371,7 @@ func consoleShell(p Page, me Me) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -382,7 +408,7 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var16 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var18 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { @@ -394,51 +420,51 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var17 string - templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.title")) + var templ_7745c5c3_Var19 string + templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.title")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 105, Col: 72} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 106, Col: 72} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var18 string - templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.heading")) + var templ_7745c5c3_Var20 string + templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.heading")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 107, Col: 114} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 108, Col: 114} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if me.TOTP { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "

● ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "

● ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var19 string - templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.active")) + var templ_7745c5c3_Var21 string + templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.active")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 109, Col: 98} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 110, Col: 98} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -446,25 +472,25 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer templ_7745c5c3_Buffer := templ.GetBuffer() var templ_7745c5c3_ElementScripts []templ.ComponentScript - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "

= 3)} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var20...) + var templ_7745c5c3_Var22 = []any{"mb-6 text-sm", templ.KV("text-down", me.RecoveryCodesLeft < 3), templ.KV("text-muted", me.RecoveryCodesLeft >= 3)} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var22...) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var21 string - templ_7745c5c3_Var21, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var20).String()).Resolve(ctx) + var templ_7745c5c3_Var23 string + templ_7745c5c3_Var23, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var22).String()).Resolve(ctx) if templ_7745c5c3_Err != nil { return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 1, Col: 0} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var21) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var23) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "\"") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "\"") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -478,33 +504,33 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud } templ.ReleaseBuffer(templ_7745c5c3_Buffer) } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, ">") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, ">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var22 string - templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.left", "Count", me.RecoveryCodesLeft)) + var templ_7745c5c3_Var24 string + templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.left", "Count", me.RecoveryCodesLeft)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 111, Col: 75} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 112, Col: 75} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var23 string - templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.regenerate")) + var templ_7745c5c3_Var25 string + templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.regenerate")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 114, Col: 116} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 115, Col: 116} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -528,20 +554,20 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var24 string - templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.disable")) + var templ_7745c5c3_Var26 string + templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.disable")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 124, Col: 109} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 125, Col: 109} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -561,51 +587,51 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "

● ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var25 string - templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.inactive")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 133, Col: 105} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var28 string - templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.heading")) + var templ_7745c5c3_Var30 string + templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.heading")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 150, Col: 113} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 151, Col: 113} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if len(identities) == 0 { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var29 string - templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.none")) + var templ_7745c5c3_Var31 string + templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.none")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 152, Col: 73} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 153, Col: 73} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } if canLink { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "\" class=\"inline-block border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var33 string - templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.link")) + var templ_7745c5c3_Var35 string + templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.link")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 161, Col: 190} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 162, Col: 190} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -747,20 +773,20 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var34 string - templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.activity_intro")) + var templ_7745c5c3_Var36 string + templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.activity_intro")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 166, Col: 88} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 167, Col: 88} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -768,7 +794,7 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -778,7 +804,7 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud } return nil }) - templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var16), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var18), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -805,33 +831,33 @@ func recoveryOutput() templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -856,46 +882,46 @@ func policyBanner(msgID, actionID, href string) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var39 string - templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, msgID)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 186, Col: 23} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var39)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var41 string - templ_7745c5c3_Var41, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, actionID)) + templ_7745c5c3_Var41, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, msgID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 187, Col: 95} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 187, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var41)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var43 string + templ_7745c5c3_Var43, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, actionID)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 188, Col: 95} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var43)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 73, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -920,46 +946,46 @@ func settingsLink(href, titleID, hintID string) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 72, "") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var44 string - templ_7745c5c3_Var44, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, titleID)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 194, Col: 56} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var44)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 75, "\" class=\"block border border-rule p-4 hover:border-ink\">") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var46 string + templ_7745c5c3_Var46, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, titleID)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 195, Col: 56} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var46)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 76, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var47 string + templ_7745c5c3_Var47, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, hintID)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 196, Col: 67} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var47)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -985,7 +1011,7 @@ func SettingsIndex(p Page, me Me) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var47 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var49 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { @@ -1001,7 +1027,7 @@ func SettingsIndex(p Page, me Me) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 76, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 78, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1067,13 +1093,13 @@ func SettingsIndex(p Page, me Me) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 79, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return nil }) - templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var47), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var49), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }