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