Remove comments and update path.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// internal/handlers/account/signup.go
|
||||
package accountHandler
|
||||
|
||||
import (
|
||||
@@ -20,7 +19,6 @@ import (
|
||||
"github.com/justinas/nosurf"
|
||||
)
|
||||
|
||||
// kept for handler-local parsing only (NOT stored in session)
|
||||
type registerForm struct {
|
||||
Username string
|
||||
Email string
|
||||
@@ -39,7 +37,6 @@ func SignupGet(c *gin.Context) {
|
||||
}
|
||||
ctx["CSRFToken"] = nosurf.Token(c.Request)
|
||||
|
||||
// Rehydrate maps (not structs) from session for sticky form + field errors
|
||||
if v := sm.Pop(c.Request.Context(), "register.form"); v != nil {
|
||||
if fm, ok := v.(map[string]string); ok {
|
||||
ctx["Form"] = fm
|
||||
@@ -51,11 +48,7 @@ func SignupGet(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// layout-first, finalized path
|
||||
tmpl := templateHelpers.LoadTemplateFiles(
|
||||
"web/templates/layout.html",
|
||||
"web/templates/account/signup.html",
|
||||
)
|
||||
tmpl := templateHelpers.LoadTemplateFiles("layout.html", "web/templates/account/signup.html")
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
if err := tmpl.ExecuteTemplate(c.Writer, "layout", ctx); err != nil {
|
||||
@@ -81,7 +74,6 @@ func SignupPost(c *gin.Context) {
|
||||
|
||||
errors := validateRegisterForm(db, form)
|
||||
if len(errors) > 0 {
|
||||
// ✅ Stash maps instead of a struct → gob-safe with SCS
|
||||
formMap := map[string]string{
|
||||
"username": form.Username,
|
||||
"email": form.Email,
|
||||
@@ -101,7 +93,6 @@ func SignupPost(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Hash password
|
||||
hash, err := securityHelpers.HashPassword(form.Password)
|
||||
if err != nil {
|
||||
logging.Info("❌ Hash error: %v", err)
|
||||
@@ -111,18 +102,15 @@ func SignupPost(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Create user
|
||||
id, err := usersStorage.CreateUser(db, form.Username, form.Email, hash)
|
||||
if err != nil {
|
||||
logging.Info("❌ CreateUser error: %v", err)
|
||||
// Unique constraints might still trip here
|
||||
sm.Put(r.Context(), "flash", "That username or email is already taken.")
|
||||
c.Redirect(http.StatusSeeOther, "/account/signup")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// Audit registration
|
||||
auditlogStorage.LogSignup(
|
||||
db,
|
||||
id,
|
||||
@@ -165,6 +153,6 @@ func validateRegisterForm(db *sql.DB, f registerForm) map[string]string {
|
||||
}
|
||||
|
||||
func looksLikeEmail(s string) bool {
|
||||
// Keep it simple; you can swap for a stricter validator later
|
||||
|
||||
return strings.Count(s, "@") == 1 && strings.Contains(s, ".")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user