validate email address

This commit is contained in:
Patrick Nagurny
2018-11-15 10:14:59 -05:00
parent 86c2673c29
commit cf1d312f9e

View File

@@ -7,6 +7,7 @@ import (
"github.com/sendgrid/sendgrid-go" "github.com/sendgrid/sendgrid-go"
"github.com/sendgrid/sendgrid-go/helpers/mail" "github.com/sendgrid/sendgrid-go/helpers/mail"
"log" "log"
"regexp"
) )
type UserInterface interface { type UserInterface interface {
@@ -34,6 +35,12 @@ func (model *Model) CreateUser(user *types.User) error {
return errors.New("email required") return errors.New("email required")
} }
re := regexp.MustCompile(".+@.+\\..+")
if re.FindString(user.Email) == "" {
return errors.New("invalid email address")
}
if user.Password == "" { if user.Password == "" {
return errors.New("password required") return errors.New("password required")
} }