diff --git a/handlers.go b/handlers.go index 1615d0e..7f3f8a4 100644 --- a/handlers.go +++ b/handlers.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "os" + "strings" ) // RegistrationRequest represents the incoming registration request. @@ -78,3 +79,24 @@ func registerHandler(w http.ResponseWriter, r *http.Request) { "message": "User registered successfully. Please check your email to set your password.", }) } + +func validateEmailDomain(email string) bool { + allowedDomains := os.Getenv("ALLOWED_DOMAINS") + if allowedDomains == "" { + return false + } + + parts := strings.Split(email, "@") + if len(parts) != 2 { + return false // Invalid email format + } + + domain := parts[1] + allowed := strings.Split(allowedDomains, ",") + for _, allowedDomain := range allowed { + if strings.TrimSpace(domain) == strings.TrimSpace(allowedDomain) { + return true + } + } + return false +}