diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-01-14 08:24:47 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2016-01-14 08:24:47 -0500 |
commit | 7d383319df2adf578eb4b2b29555846a7c848049 (patch) | |
tree | d8283b12c2a1b14c18da4ae446f5c2ca0e5d0af5 /api/user.go | |
parent | 53b0cd8f2a24798c67505aa447b1d53b9f14197e (diff) | |
parent | c26edcf6786fd8aa1535c09e9581fc6417cddda4 (diff) | |
download | chat-7d383319df2adf578eb4b2b29555846a7c848049.tar.gz chat-7d383319df2adf578eb4b2b29555846a7c848049.tar.bz2 chat-7d383319df2adf578eb4b2b29555846a7c848049.zip |
Merge pull request #1887 from mattermost/editions
Editions
Diffstat (limited to 'api/user.go')
-rw-r--r-- | api/user.go | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/api/user.go b/api/user.go index d014ab995..a6b4fb654 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,29 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) { } +func CheckUserDomain(user *model.User, domains string) bool { + if len(domains) == 0 { + return true + } + + 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 |