summaryrefslogtreecommitdiffstats
path: root/api/user.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-02-03 07:33:43 -0500
committerJoram Wilander <jwawilander@gmail.com>2016-02-03 07:33:43 -0500
commit4a09adeb391b23c7e850fec96a2e8a731b70d755 (patch)
treeca9cc2410dc17de823d923c9e0ff74fea16d2a82 /api/user.go
parentd31ae207389b7402debbcaa40bb691e86023f1ba (diff)
parentb013f02209c7c128a35d1c54f2d4a7d6a9701f72 (diff)
downloadchat-4a09adeb391b23c7e850fec96a2e8a731b70d755.tar.gz
chat-4a09adeb391b23c7e850fec96a2e8a731b70d755.tar.bz2
chat-4a09adeb391b23c7e850fec96a2e8a731b70d755.zip
Merge pull request #1991 from rgarmsen2295/plt-976
PLT-976 Adds ability to sign in with username
Diffstat (limited to 'api/user.go')
-rw-r--r--api/user.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/api/user.go b/api/user.go
index 6ad0f67ac..91c8c022a 100644
--- a/api/user.go
+++ b/api/user.go
@@ -444,6 +444,38 @@ func LoginByEmail(c *Context, w http.ResponseWriter, r *http.Request, email, nam
return nil
}
+func LoginByUsername(c *Context, w http.ResponseWriter, r *http.Request, username, name, password, deviceId string) *model.User {
+ var team *model.Team
+
+ if result := <-Srv.Store.Team().GetByName(name); result.Err != nil {
+ c.Err = result.Err
+ return nil
+ } else {
+ team = result.Data.(*model.Team)
+ }
+
+ if result := <-Srv.Store.User().GetByUsername(team.Id, username); result.Err != nil {
+ c.Err = result.Err
+ c.Err.StatusCode = http.StatusForbidden
+ return nil
+ } else {
+ user := result.Data.(*model.User)
+
+ if len(user.AuthData) != 0 {
+ c.Err = model.NewLocAppError("LoginByUsername", "api.user.login_by_email.sign_in.app_error",
+ map[string]interface{}{"AuthService": user.AuthService}, "")
+ return nil
+ }
+
+ if checkUserLoginAttempts(c, user) && checkUserPassword(c, user, password) {
+ Login(c, w, r, user, deviceId)
+ return user
+ }
+ }
+
+ return nil
+}
+
func LoginByOAuth(c *Context, w http.ResponseWriter, r *http.Request, service string, userData io.ReadCloser, team *model.Team) *model.User {
authData := ""
provider := einterfaces.GetOauthProvider(service)
@@ -629,6 +661,8 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
user = LoginById(c, w, r, props["id"], props["password"], props["device_id"])
} else if len(props["email"]) != 0 && len(props["name"]) != 0 {
user = LoginByEmail(c, w, r, props["email"], props["name"], props["password"], props["device_id"])
+ } else if len(props["username"]) != 0 && len(props["name"]) != 0 {
+ user = LoginByUsername(c, w, r, props["username"], props["name"], props["password"], props["device_id"])
} else {
c.Err = model.NewLocAppError("login", "api.user.login.not_provided.app_error", nil, "")
c.Err.StatusCode = http.StatusForbidden