diff options
author | JoramWilander <jwawilander@gmail.com> | 2016-01-13 10:54:12 -0500 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2016-01-14 08:24:09 -0500 |
commit | 874d120535a615afddeb80599b7d2d982959ffdb (patch) | |
tree | 226c38cf4d42068733c3c661d3983963a2df4272 /api | |
parent | 9110dd54a15f3d0fcf6f60936e01d816b667b93c (diff) | |
download | chat-874d120535a615afddeb80599b7d2d982959ffdb.tar.gz chat-874d120535a615afddeb80599b7d2d982959ffdb.tar.bz2 chat-874d120535a615afddeb80599b7d2d982959ffdb.zip |
Add some unit tests
Diffstat (limited to 'api')
-rw-r--r-- | api/user.go | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/api/user.go b/api/user.go index d014ab995..786414227 100644 --- a/api/user.go +++ b/api/user.go @@ -122,6 +122,11 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) { user.EmailVerified = true } + if !CheckUserDomain(user, utils.Cfg.TeamSettings.RestrictCreationToDomains) { + c.Err = model.NewAppError("createUser", "The email you provided does not belong to an accepted domain. Please contact your administrator or sign up with a different email.", "") + return + } + ruser, err := CreateUser(team, user) if err != nil { c.Err = err @@ -136,19 +141,25 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) { } +func CheckUserDomain(user *model.User, domains string) bool { + domainArray := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(domains, "@", " ", -1), ",", " ", -1)))) + + matched := false + for _, d := range domainArray { + if strings.HasSuffix(user.Email, "@"+d) { + matched = true + break + } + } + + return matched +} + func IsVerifyHashRequired(user *model.User, team *model.Team, hash string) bool { shouldVerifyHash := true if team.Type == model.TEAM_INVITE && len(team.AllowedDomains) > 0 && len(hash) == 0 && user != nil { - domains := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(team.AllowedDomains, "@", " ", -1), ",", " ", -1)))) - - matched := false - for _, d := range domains { - if strings.HasSuffix(user.Email, "@"+d) { - matched = true - break - } - } + matched := CheckUserDomain(user, team.AllowedDomains) if matched { shouldVerifyHash = false |