1
0
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:
Jesús Espino 2021-03-18 11:37:48 +01:00 committed by GitHub
commit a66d16d81b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 10 deletions

2
.gitignore vendored
View File

@ -60,3 +60,5 @@ win/dist
webapp/cypress/screenshots
webapp/cypress/videos
server/swagger/clients
server/vendor
.idea

View File

@ -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

View File

@ -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

View 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)
}