From 1e9cb5ffc48076a6c71283466841d2cc67888f82 Mon Sep 17 00:00:00 2001 From: "corrado.mulas" Date: Wed, 20 Nov 2024 00:36:19 +0100 Subject: [PATCH] First commit --- handlers.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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 +}