Phase 10, part 3: signing in and out, resets, locks and two-factor

The server edition now starts. Sign-in by email and password, limited per
address and per IP; ten failures in a row lock the account and email its
owner, and a reset by email (or an admin) unlocks it. Settings → Your
account has the profile, the password, where you're signed in, and
two-factor sign-in with an authenticator app (TOTP, from a QR code) and
ten recovery codes. The app's own mail goes through SUPERMARKET_MAIL_URL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 09:01:29 -07:00
co-authored by Claude Opus 5.5
parent 72455438c9
commit 8040512a18
26 changed files with 1991 additions and 12 deletions
+27 -1
View File
@@ -27,6 +27,7 @@ import (
"supermarket/internal/api/reddit"
"supermarket/internal/api/twitter"
"supermarket/internal/appmail"
"supermarket/internal/core"
"supermarket/internal/db"
"supermarket/internal/legacy"
@@ -59,7 +60,8 @@ type Server struct {
MCPToken string
MCPSocket string // the MCP socket's path on the host, for Hermes' config
MCP http.Handler
Restart func() // stops the app so Docker starts it again; nil in tests
Mail appmail.Sender // the app's own mail (invitations, resets); nil on local
Restart func() // stops the app so Docker starts it again; nil in tests
Log *slog.Logger
// What the legacy import did at startup, or why it failed.
@@ -140,6 +142,23 @@ func (s *Server) Handler() (http.Handler, error) {
// Signing in (the server edition).
mux.HandleFunc("GET /setup/{token}", s.setupPage)
mux.HandleFunc("POST /setup/{token}", s.setupSave)
mux.HandleFunc("GET /signin", s.signinPage)
mux.HandleFunc("POST /signin", s.signin)
mux.HandleFunc("POST /signin/code", s.signinCode)
mux.HandleFunc("POST /signout", s.signout)
mux.HandleFunc("GET /forgot", s.forgotPage)
mux.HandleFunc("POST /forgot", s.forgot)
mux.HandleFunc("GET /reset/{token}", s.resetPage)
mux.HandleFunc("POST /reset/{token}", s.reset)
mux.HandleFunc("GET /settings/account", s.accountPage)
mux.HandleFunc("POST /settings/account/profile", s.accountProfile)
mux.HandleFunc("POST /settings/account/password", s.accountPassword)
mux.HandleFunc("POST /settings/account/sessions/end-others", s.accountEndOthers)
mux.HandleFunc("POST /settings/account/sessions/{id}/end", s.accountEndSession)
mux.HandleFunc("GET /settings/account/two-factor", s.twoFactorPage)
mux.HandleFunc("POST /settings/account/two-factor", s.twoFactorOn)
mux.HandleFunc("POST /settings/account/two-factor/off", s.twoFactorOff)
mux.HandleFunc("POST /settings/account/recovery-codes", s.recoveryCodes)
mux.HandleFunc("GET /search", s.searchPage)
@@ -609,6 +628,13 @@ func (s *Server) fragment(w http.ResponseWriter, r *http.Request, page, name str
var flashes = map[string]string{
"saved": "Saved.",
"welcome": "Welcome: you're the owner. Start with the company's profile.",
"signed-out": "Signed out.",
"password-reset": "Your new password is saved: sign in with it.",
"password-changed": "Password changed. You're signed out everywhere else.",
"session-ended": "Signed out there.",
"sessions-ended": "Signed out everywhere else.",
"two-factor-off": "Two-factor sign-in is off.",
"codes-low": "You're running out of recovery codes: make new ones below.",
"deleted": "Deleted.",
"x-connected": "X is connected.",
"li-connected": "LinkedIn is connected.",