summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2016-03-07 14:59:15 -0800
committer=Corey Hulen <corey@hulen.com>2016-03-07 14:59:15 -0800
commit777012eee42186316bc68b0ea1c8232601962bc4 (patch)
tree9eae93ee873762038667a3be93001bea4612e195 /api
parent0387ac799792fdd0684b863bb029813bbb3eccf7 (diff)
downloadchat-777012eee42186316bc68b0ea1c8232601962bc4.tar.gz
chat-777012eee42186316bc68b0ea1c8232601962bc4.tar.bz2
chat-777012eee42186316bc68b0ea1c8232601962bc4.zip
PLT-1830 Adding ability to create team with ldap
Diffstat (limited to 'api')
-rw-r--r--api/team.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/api/team.go b/api/team.go
index 052d6e698..2f680dc76 100644
--- a/api/team.go
+++ b/api/team.go
@@ -8,6 +8,7 @@ import (
"fmt"
l4g "github.com/alecthomas/log4go"
"github.com/gorilla/mux"
+ "github.com/mattermost/platform/einterfaces"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
@@ -25,6 +26,7 @@ func InitTeam(r *mux.Router) {
sr := r.PathPrefix("/teams").Subrouter()
sr.Handle("/create", ApiAppHandler(createTeam)).Methods("POST")
sr.Handle("/create_from_signup", ApiAppHandler(createTeamFromSignup)).Methods("POST")
+ sr.Handle("/create_with_ldap", ApiAppHandler(createTeamWithLdap)).Methods("POST")
sr.Handle("/create_with_sso/{service:[A-Za-z]+}", ApiAppHandler(createTeamFromSSO)).Methods("POST")
sr.Handle("/signup", ApiAppHandler(signupTeam)).Methods("POST")
sr.Handle("/all", ApiUserRequired(getAll)).Methods("GET")
@@ -244,6 +246,80 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
+func createTeamWithLdap(c *Context, w http.ResponseWriter, r *http.Request) {
+ ldap := einterfaces.GetLdapInterface()
+ if ldap == nil {
+ c.Err = model.NewLocAppError("createTeamWithLdap", "ent.ldap.do_login.licence_disable.app_error", nil, "")
+ return
+ }
+
+ teamSignup := model.TeamSignupFromJson(r.Body)
+
+ if teamSignup == nil {
+ c.SetInvalidParam("createTeam", "teamSignup")
+ return
+ }
+
+ teamSignup.Team.PreSave()
+
+ if err := teamSignup.Team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); err != nil {
+ c.Err = err
+ return
+ }
+
+ if !isTeamCreationAllowed(c, teamSignup.Team.Email) {
+ return
+ }
+
+ teamSignup.Team.Id = ""
+
+ found := FindTeamByName(c, teamSignup.Team.Name, "true")
+ if c.Err != nil {
+ return
+ }
+
+ if found {
+ c.Err = model.NewLocAppError("createTeamFromSignup", "api.team.create_team_from_signup.unavailable.app_error", nil, "d="+teamSignup.Team.Name)
+ return
+ }
+
+ user, err := ldap.GetUser(teamSignup.User.Username)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ err = ldap.CheckPassword(teamSignup.User.Username, teamSignup.User.Password)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ if result := <-Srv.Store.Team().Save(&teamSignup.Team); result.Err != nil {
+ c.Err = result.Err
+ return
+ } else {
+ rteam := result.Data.(*model.Team)
+
+ if _, err := CreateDefaultChannels(c, rteam.Id); err != nil {
+ c.Err = nil
+ return
+ }
+
+ user.TeamId = rteam.Id
+ ruser, err := CreateUser(rteam, user)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ teamSignup.Team = *rteam
+ teamSignup.User = *ruser
+
+ w.Write([]byte(teamSignup.ToJson()))
+ }
+}
+
func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
team := model.TeamFromJson(r.Body)
rteam := CreateTeam(c, team)