diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2023-09-10 13:49:34 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2023-09-10 13:49:34 +0530 |
commit | 794a9c07ffc7dc72993f5240796dfe643d73ed82 (patch) | |
tree | 26e8175982cb00dcd3dc4f099b6b7309ddda2fa1 /user/validators.go | |
parent | 8f2180401fd05ba63633d9559dc156f5ca1573ba (diff) |
validating email upon user sign upv0.0.7
Diffstat (limited to 'user/validators.go')
-rw-r--r-- | user/validators.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/user/validators.go b/user/validators.go index 88239c6..647da06 100644 --- a/user/validators.go +++ b/user/validators.go @@ -19,6 +19,7 @@ package user import ( "strings" + "net/mail" e "errors" "github.com/spf13/viper" "vidhukant.com/openbills/errors" @@ -73,9 +74,15 @@ func (u *User) validate() error { u.IsVerified = false // TODO: validate username length and stuff - // TODO: validate if email is valid var err error + + // validate email + _, err = mail.ParseAddress(u.Email) + if err != nil { + return errors.ErrInvalidEmail + } + for _, i := range [][]string{{"username", u.Username}, {"email", u.Email}} { err = validateUserField(i[0], i[1]) if err != nil { |