mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-15 09:14:11 +02:00
Merge pull request #85 from lutfuahmet/main
Register Request email validation
This commit is contained in:
commit
a66d16d81b
2
.gitignore
vendored
2
.gitignore
vendored
@ -60,3 +60,5 @@ win/dist
|
||||
webapp/cypress/screenshots
|
||||
webapp/cypress/videos
|
||||
server/swagger/clients
|
||||
server/vendor
|
||||
.idea
|
||||
|
@ -71,17 +71,17 @@ type RegisterRequest struct {
|
||||
}
|
||||
|
||||
func (rd *RegisterRequest) IsValid() error {
|
||||
if rd.Username == "" {
|
||||
return errors.New("Username is required")
|
||||
if strings.TrimSpace(rd.Username) == "" {
|
||||
return errors.New("username is required")
|
||||
}
|
||||
if rd.Email == "" {
|
||||
return errors.New("Email is required")
|
||||
if strings.TrimSpace(rd.Email) == "" {
|
||||
return errors.New("email is required")
|
||||
}
|
||||
if !strings.Contains(rd.Email, "@") {
|
||||
return errors.New("Invalid email format")
|
||||
if auth.IsEmailValid(rd.Email) {
|
||||
return errors.New("invalid email format")
|
||||
}
|
||||
if rd.Password == "" {
|
||||
return errors.New("Password is required")
|
||||
return errors.New("password is required")
|
||||
}
|
||||
if err := isValidPassword(rd.Password); err != nil {
|
||||
return err
|
||||
|
@ -4,11 +4,11 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/Masterminds/squirrel v1.4.0
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
|
||||
github.com/go-ldap/ldap v3.0.3+incompatible // indirect
|
||||
github.com/golang-migrate/migrate v3.5.4+incompatible
|
||||
github.com/golang-migrate/migrate v3.5.4+incompatible // indirect
|
||||
github.com/golang-migrate/migrate/v4 v4.13.0
|
||||
github.com/golang/gddo v0.0.0-20200831202555-721e228c7686
|
||||
github.com/golang/gddo v0.0.0-20200831202555-721e228c7686 // indirect
|
||||
github.com/golang/mock v1.4.4
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/gorilla/mux v1.8.0
|
||||
|
15
server/services/auth/email.go
Normal file
15
server/services/auth/email.go
Normal file
@ -0,0 +1,15 @@
|
||||
package auth
|
||||
|
||||
import "regexp"
|
||||
|
||||
var (
|
||||
emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
|
||||
)
|
||||
|
||||
// IsEmailValid checks if the email provided passes the required structure and length.
|
||||
func IsEmailValid(e string) bool {
|
||||
if len(e) < 3 && len(e) > 254 {
|
||||
return false
|
||||
}
|
||||
return emailRegex.MatchString(e)
|
||||
}
|
Loading…
Reference in New Issue
Block a user