diff options
Diffstat (limited to 'app/controllers/welcome_controller.rb')
-rw-r--r-- | app/controllers/welcome_controller.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 5fce0cf..ad9cd95 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -102,20 +102,27 @@ class WelcomeController < ApplicationController # Set @current_user to existing or new User record from SSO user info def find_or_create_current_user - @current_user = User.find_by(external_id: @sso.user_info[:external_id]) || + user_data = { + external_id: @sso.user_info[:external_id], + avatar_url: @sso.user_info[:avatar_url], + email: @sso.user_info[:email], + name: @sso.user_info[:name], + username: @sso.user_info[:username] + } + + @current_user = User.find_by(external_id: user_data[:external_id]) || begin Rails.logger.info('new user...') - u = User.create( - external_id: @sso.user_info[:external_id], - avatar_url: @sso.user_info[:avatar_url], - email: @sso.user_info[:email], - name: @sso.user_info[:name], - username: @sso.user_info[:username]) + u = User.create(user_data) Rails.logger.info('created user %s' % u.inspect) u rescue Exception => e Rails.logger.warning("#{e.type}: #{e.message}") end + + user_data.reverse_merge!(@current_user.attributes.symbolize_keys) + @current_user.update(user_data) if user_data != @current_user.attributes + @current_user end # Update user agents |