From 92677e8d5cf5ec97696e22e09926ebe8a13c7e50 Mon Sep 17 00:00:00 2001 From: James Brechtel Date: Wed, 19 Aug 2026 10:19:55 -0400 Subject: [PATCH] Gate sign-up on AllowSignup field instead of user count --- handler/auth.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/handler/auth.go b/handler/auth.go index 0051ba4..e9ca996 100644 --- a/handler/auth.go +++ b/handler/auth.go @@ -48,14 +48,14 @@ func (ss *SessionStore) Delete(token string) { // --- Handlers --- type AuthHandler struct { - Store *store.Store - Sessions *SessionStore - Tpl *Templates + Store *store.Store + Sessions *SessionStore + Tpl *Templates + AllowSignup bool } func (h *AuthHandler) ServeSignup(w http.ResponseWriter, r *http.Request) { - count, err := h.Store.UserCount() - if err == nil && count > 0 { + if !h.AllowSignup { http.Redirect(w, r, "/signin", http.StatusSeeOther) return } @@ -97,14 +97,13 @@ func (h *AuthHandler) ServeSignup(w http.ResponseWriter, r *http.Request) { } } -func (h *AuthHandler) hasUsers() bool { - count, err := h.Store.UserCount() - return err == nil && count > 0 +func (h *AuthHandler) allowSignup() bool { + return h.AllowSignup } func (h *AuthHandler) ServeSignin(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodGet { - h.Tpl.Render(w, "signin", map[string]any{"HasUser": h.hasUsers()}) + h.Tpl.Render(w, "signin", map[string]any{"HasUser": h.allowSignup()}) return } @@ -114,12 +113,12 @@ func (h *AuthHandler) ServeSignin(w http.ResponseWriter, r *http.Request) { user, err := h.Store.UserByEmail(email) if err != nil { - h.Tpl.Render(w, "signin", map[string]any{"Error": "Invalid email or password.", "HasUser": h.hasUsers()}) + h.Tpl.Render(w, "signin", map[string]any{"Error": "Invalid email or password.", "HasUser": h.allowSignup()}) return } if err := bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(password)); err != nil { - h.Tpl.Render(w, "signin", map[string]any{"Error": "Invalid email or password.", "HasUser": h.hasUsers()}) + h.Tpl.Render(w, "signin", map[string]any{"Error": "Invalid email or password.", "HasUser": h.allowSignup()}) return }