feat(backend): add email validator package

Add ValidateEmail and NormalizeGiftCardCode functions with comprehensive tests. Migrate guest.go from inline mail.ParseAddress to validators.ValidateEmail.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-06-12 10:50:34 +01:00
co-authored by Sisyphus
parent 834c0f1da0
commit 5f0248540f
3 changed files with 202 additions and 7 deletions
+5 -7
View File
@@ -6,7 +6,6 @@ import (
"errors"
"log"
"net/http"
"net/mail"
"regexp"
"strings"
@@ -69,10 +68,9 @@ func CreateGuestUserHandler(w http.ResponseWriter, r *http.Request) {
return
}
// Validate email format (contains @ and .)
_, err := mail.ParseAddress(req.Email)
if err != nil {
http.Error(w, "invalid email format", http.StatusBadRequest)
// Validate email format
if err := validators.ValidateEmail(req.Email); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
@@ -140,8 +138,8 @@ func CheckEmailHandler(w http.ResponseWriter, r *http.Request) {
return
}
if _, err := mail.ParseAddress(email); err != nil {
http.Error(w, "invalid email format", http.StatusBadRequest)
if err := validators.ValidateEmail(email); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}