summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2016-02-04 09:24:41 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2016-02-04 09:24:41 -0500
commit5e83be02baceca6f386115fe20475f593c90ee3c (patch)
tree6381fc04fe3964f382a6d4f4ead9260b41378349 /store
parent87e6357265422cc8549c39bc3fe3b52c6731fba5 (diff)
parenta4e7d02cec91613792e1f2c79d3919018d999e32 (diff)
downloadchat-5e83be02baceca6f386115fe20475f593c90ee3c.tar.gz
chat-5e83be02baceca6f386115fe20475f593c90ee3c.tar.bz2
chat-5e83be02baceca6f386115fe20475f593c90ee3c.zip
Merge pull request #2059 from mattermost/plt-1732
PLT-1732 Update user email when switching to SSO
Diffstat (limited to 'store')
-rw-r--r--store/sql_user_store.go21
-rw-r--r--store/sql_user_store_test.go2
-rw-r--r--store/store.go2
3 files changed, 21 insertions, 4 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 0b6970c96..b1544289d 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -305,7 +305,7 @@ func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int)
return storeChannel
}
-func (us SqlUserStore) UpdateAuthData(userId, service, authData string) StoreChannel {
+func (us SqlUserStore) UpdateAuthData(userId, service, authData, email string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -314,7 +314,24 @@ func (us SqlUserStore) UpdateAuthData(userId, service, authData string) StoreCha
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 {
+ query := `
+ UPDATE
+ Users
+ SET
+ Password = '',
+ LastPasswordUpdate = :LastPasswordUpdate,
+ UpdateAt = :UpdateAt,
+ FailedAttempts = 0,
+ AuthService = :AuthService,
+ AuthData = :AuthData`
+
+ if len(email) != 0 {
+ query += ", Email = :Email"
+ }
+
+ query += " WHERE Id = :UserId"
+
+ if _, err := us.GetMaster().Exec(query, map[string]interface{}{"LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId, "AuthService": service, "AuthData": authData, "Email": email}); err != nil {
result.Err = model.NewLocAppError("SqlUserStore.UpdateAuthData", "store.sql_user.update_auth_data.app_error", nil, "id="+userId+", "+err.Error())
} else {
result.Data = userId
diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go
index d1ee5e647..2350bad30 100644
--- a/store/sql_user_store_test.go
+++ b/store/sql_user_store_test.go
@@ -402,7 +402,7 @@ func TestUserStoreUpdateAuthData(t *testing.T) {
service := "someservice"
authData := "1"
- if err := (<-store.User().UpdateAuthData(u1.Id, service, authData)).Err; err != nil {
+ if err := (<-store.User().UpdateAuthData(u1.Id, service, authData, "")).Err; err != nil {
t.Fatal(err)
}
diff --git a/store/store.go b/store/store.go
index cfc679706..2aa627734 100644
--- a/store/store.go
+++ b/store/store.go
@@ -111,7 +111,7 @@ type UserStore interface {
UpdateLastActivityAt(userId string, time int64) StoreChannel
UpdateUserAndSessionActivity(userId string, sessionId string, time int64) StoreChannel
UpdatePassword(userId, newPassword string) StoreChannel
- UpdateAuthData(userId, service, authData string) StoreChannel
+ UpdateAuthData(userId, service, authData, email string) StoreChannel
Get(id string) StoreChannel
GetProfiles(teamId string) StoreChannel
GetByEmail(teamId string, email string) StoreChannel