summaryrefslogtreecommitdiffstats
path: root/web/web.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-08-28 09:14:37 -0400
committerChristopher Speller <crspeller@gmail.com>2015-08-28 09:14:37 -0400
commit75af5d4536cc414d171c2fe6dca78e455eb18b37 (patch)
tree4e00cf97b5f4f570b1901093bfa4e208749932a0 /web/web.go
parentd107b392a6309a41eac6cd7d07d720a21968eb56 (diff)
parentf5fec3a157e6c9146a0c4e28dd5f70e6c066affd (diff)
downloadchat-75af5d4536cc414d171c2fe6dca78e455eb18b37.tar.gz
chat-75af5d4536cc414d171c2fe6dca78e455eb18b37.tar.bz2
chat-75af5d4536cc414d171c2fe6dca78e455eb18b37.zip
Merge pull request #496 from mattermost/mm-2015
MM-2015 Added the ability to create a team with SSO services and added the ability to turn off email sign up.
Diffstat (limited to 'web/web.go')
-rw-r--r--web/web.go45
1 files changed, 38 insertions, 7 deletions
diff --git a/web/web.go b/web/web.go
index dc2b5dced..03dbdde6a 100644
--- a/web/web.go
+++ b/web/web.go
@@ -145,6 +145,7 @@ func root(c *api.Context, w http.ResponseWriter, r *http.Request) {
if len(c.Session.UserId) == 0 {
page := NewHtmlTemplatePage("signup_team", "Signup")
+ page.Props["AuthServices"] = model.ArrayToJson(utils.GetAllowedAuthServices())
page.Render(c, w)
} else {
page := NewHtmlTemplatePage("home", "Home")
@@ -160,6 +161,7 @@ func signup(c *api.Context, w http.ResponseWriter, r *http.Request) {
}
page := NewHtmlTemplatePage("signup_team", "Signup")
+ page.Props["AuthServices"] = model.ArrayToJson(utils.GetAllowedAuthServices())
page.Render(c, w)
}
@@ -529,23 +531,52 @@ func signupCompleteOAuth(c *api.Context, w http.ResponseWriter, r *http.Request)
return
}
- if result := <-api.Srv.Store.User().GetByAuth(team.Id, user.AuthData, service); result.Err == nil {
+ suchan := api.Srv.Store.User().GetByAuth(team.Id, user.AuthData, service)
+ euchan := api.Srv.Store.User().GetByEmail(team.Id, user.Email)
+
+ if team.Email == "" {
+ team.Email = user.Email
+ if result := <-api.Srv.Store.Team().Update(team); result.Err != nil {
+ c.Err = result.Err
+ return
+ }
+ } else {
+ found := true
+ count := 0
+ for found {
+ if found = api.IsUsernameTaken(user.Username, team.Id); c.Err != nil {
+ return
+ } else if found {
+ user.Username = user.Username + strconv.Itoa(count)
+ count += 1
+ }
+ }
+ }
+
+ if result := <-suchan; result.Err == nil {
c.Err = model.NewAppError("signupCompleteOAuth", "This "+service+" account has already been used to sign up for team "+team.DisplayName, "email="+user.Email)
return
}
- if result := <-api.Srv.Store.User().GetByEmail(team.Id, user.Email); result.Err == nil {
+ if result := <-euchan; result.Err == nil {
c.Err = model.NewAppError("signupCompleteOAuth", "Team "+team.DisplayName+" already has a user with the email address attached to your "+service+" account", "email="+user.Email)
return
}
user.TeamId = team.Id
- page := NewHtmlTemplatePage("signup_user_oauth", "Complete User Sign Up")
- page.Props["User"] = user.ToJson()
- page.Props["TeamName"] = team.Name
- page.Props["TeamDisplayName"] = team.DisplayName
- page.Render(c, w)
+ ruser := api.CreateUser(c, team, user)
+ if c.Err != nil {
+ return
+ }
+
+ api.Login(c, w, r, ruser, "")
+
+ if c.Err != nil {
+ return
+ }
+
+ root(c, w, r)
}
}