diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-01-04 15:55:51 -0500 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-01-04 15:55:51 -0500 |
commit | 67db3ca8ce5e78ee55c37a3dbfb8e5d44037a324 (patch) | |
tree | 6ffac556a09192e7042d7ab2c184382286338c90 /store/sql_user_store.go | |
parent | 07efe758609929e662185199e8c5a273b0fb0007 (diff) | |
parent | a6ae90ac2a74871331707751e823b4746136ff09 (diff) | |
download | chat-67db3ca8ce5e78ee55c37a3dbfb8e5d44037a324.tar.gz chat-67db3ca8ce5e78ee55c37a3dbfb8e5d44037a324.tar.bz2 chat-67db3ca8ce5e78ee55c37a3dbfb8e5d44037a324.zip |
Merge pull request #1745 from mattermost/plt-1118
PLT-1118 Add ability to switch between SSO and email account
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r-- | store/sql_user_store.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 82a2ccd05..88c4f954b 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -266,7 +266,7 @@ func (us SqlUserStore) UpdatePassword(userId, hashedPassword string) StoreChanne updateAt := model.GetMillis() - if _, err := us.GetMaster().Exec("UPDATE Users SET Password = :Password, LastPasswordUpdate = :LastPasswordUpdate, UpdateAt = :UpdateAt, FailedAttempts = 0 WHERE Id = :UserId AND AuthData = ''", map[string]interface{}{"Password": hashedPassword, "LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId}); err != nil { + if _, err := us.GetMaster().Exec("UPDATE Users SET Password = :Password, LastPasswordUpdate = :LastPasswordUpdate, UpdateAt = :UpdateAt, AuthData = '', AuthService = '', FailedAttempts = 0 WHERE Id = :UserId", map[string]interface{}{"Password": hashedPassword, "LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId}); err != nil { result.Err = model.NewAppError("SqlUserStore.UpdatePassword", "We couldn't update the user password", "id="+userId+", "+err.Error()) } else { result.Data = userId @@ -298,6 +298,28 @@ func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int) return storeChannel } +func (us SqlUserStore) UpdateAuthData(userId, service, authData string) StoreChannel { + + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + updateAt := model.GetMillis() + + if _, err := us.GetMaster().Exec("UPDATE Users SET Password = '', LastPasswordUpdate = :LastPasswordUpdate, UpdateAt = :UpdateAt, FailedAttempts = 0, AuthService = :AuthService, AuthData = :AuthData WHERE Id = :UserId", map[string]interface{}{"LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId, "AuthService": service, "AuthData": authData}); err != nil { + result.Err = model.NewAppError("SqlUserStore.UpdateAuthData", "We couldn't update the auth data", "id="+userId+", "+err.Error()) + } else { + result.Data = userId + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (us SqlUserStore) Get(id string) StoreChannel { storeChannel := make(StoreChannel) |