summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2016-02-03 10:32:37 -0500
committerJoramWilander <jwawilander@gmail.com>2016-02-03 10:32:37 -0500
commit3425aa3e5d814e0c6d377a7faa07de6451216be1 (patch)
tree1ea1f34b9660078d3f5ec4062df879e01f947a50 /store
parentf7fddd6cce43ec75599eb4aa463276f18eb4ca28 (diff)
downloadchat-3425aa3e5d814e0c6d377a7faa07de6451216be1.tar.gz
chat-3425aa3e5d814e0c6d377a7faa07de6451216be1.tar.bz2
chat-3425aa3e5d814e0c6d377a7faa07de6451216be1.zip
Update user email when switching to SSO
Diffstat (limited to 'store')
-rw-r--r--store/sql_user_store.go21
-rw-r--r--store/store.go2
2 files changed, 20 insertions, 3 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/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