summaryrefslogtreecommitdiffstats
path: root/app/user.go
diff options
context:
space:
mode:
authorPoornima <mpoornima@users.noreply.github.com>2017-02-27 00:18:01 +0530
committerJoram Wilander <jwawilander@gmail.com>2017-02-26 13:48:01 -0500
commitc0bb6f99f89259f6728856ace23d5dd505494b26 (patch)
tree024fb446bef25eb74763da14f8e98a6685807af6 /app/user.go
parent04f4545bbd6c9a1f85071483e96e29684871d547 (diff)
downloadchat-c0bb6f99f89259f6728856ace23d5dd505494b26.tar.gz
chat-c0bb6f99f89259f6728856ace23d5dd505494b26.tar.bz2
chat-c0bb6f99f89259f6728856ace23d5dd505494b26.zip
Updating user attributes on oauth login (#5324)
Moving update function to app package Fixing duplicate userID on create user test
Diffstat (limited to 'app/user.go')
-rw-r--r--app/user.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/user.go b/app/user.go
index 9f428089b..53e389947 100644
--- a/app/user.go
+++ b/app/user.go
@@ -27,6 +27,7 @@ import (
"github.com/golang/freetype"
"github.com/mattermost/platform/einterfaces"
"github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
)
@@ -1253,3 +1254,45 @@ func AutocompleteUsersInTeam(teamId string, term string, searchOptions map[strin
return autocomplete, nil
}
+
+func UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OauthProvider, service string, siteURL string) *model.AppError {
+ oauthUser := provider.GetUserFromJson(userData)
+
+ if oauthUser == nil {
+ return model.NewLocAppError("UpdateOAuthUserAttrs", "api.user.update_oauth_user_attrs.get_user.app_error", map[string]interface{}{"Service": service}, "")
+ }
+
+ userAttrsChanged := false
+
+ if oauthUser.Username != user.Username {
+ if existingUser, _ := GetUserByUsername(oauthUser.Username); existingUser == nil {
+ user.Username = oauthUser.Username
+ userAttrsChanged = true
+ }
+ }
+
+ if oauthUser.GetFullName() != user.GetFullName() {
+ user.FirstName = oauthUser.FirstName
+ user.LastName = oauthUser.LastName
+ userAttrsChanged = true
+ }
+
+ if oauthUser.Email != user.Email {
+ if existingUser, _ := GetUserByEmail(oauthUser.Email); existingUser == nil {
+ user.Email = oauthUser.Email
+ userAttrsChanged = true
+ }
+ }
+
+ if userAttrsChanged {
+ var result store.StoreResult
+ if result = <-Srv.Store.User().Update(user, true); result.Err != nil {
+ return result.Err
+ }
+
+ user = result.Data.([2]*model.User)[0]
+ InvalidateCacheForUser(user.Id)
+ }
+
+ return nil
+}