Permalink
Browse files

Fixed issue #2281 - O365/Office365 authentication missing given- and …

…surname.
  • Loading branch information...
znuny-robo committed Oct 11, 2018
1 parent 7dd6675 commit 6439203900024c524969b5654c52c0bdc0038d0b
Showing with 27 additions and 14 deletions.
  1. +1 −1 app/controllers/sessions_controller.rb
  2. +17 −8 app/models/authorization.rb
  3. +9 −5 app/models/user.rb
@@ -69,7 +69,7 @@ def show
user_id = session[:user_id]
end
if !user_id
if !user_id || !User.exists?(user_id)
# get models
models = SessionHelper.models()
@@ -20,17 +20,25 @@ def self.find_from_hash(hash)
)
# update username of auth entry if empty
if !auth.username && hash['info']['nickname']
if !auth.username && hash['info']['nickname'].present?
auth.update!(
username: hash['info']['nickname'],
)
end
# update image if needed
if hash['info']['image']
user = User.find(auth.user_id)
# update firstname/lastname if needed
user = User.find(auth.user_id)
if user.firstname.blank? && user.lastname.blank?
if hash['info']['first_name'].present? && hash['info']['last_name'].present?
user.firstname = hash['info']['first_name']
user.lastname = hash['info']['last_name']
elsif hash['info']['display_name'].present?
user.firstname = hash['info']['display_name']
end
end
# save/update avatar
# update image if needed
if hash['info']['image'].present?
avatar = Avatar.add(
object: 'User',
o_id: user.id,
@@ -40,13 +48,14 @@ def self.find_from_hash(hash)
updated_by_id: user.id,
created_by_id: user.id,
)
# update user link
if avatar && user.image != avatar.store_hash
user.image = avatar.store_hash
user.save
end
end
if user.changed?
user.save
end
end
auth
end
View
@@ -359,27 +359,31 @@ def self.sso(params)
def self.create_from_hash!(hash)
role_ids = Role.signup_role_ids
url = ''
hash['info']['urls']&.each_value do |local_url|
next if local_url.blank?
url = local_url
end
begin
create!(
data = {
login: hash['info']['nickname'] || hash['uid'],
firstname: hash['info']['name'],
firstname: hash['info']['name'] || hash['info']['display_name'],
email: hash['info']['email'],
image_source: hash['info']['image'],
web: url,
address: hash['info']['location'],
note: hash['info']['description'],
source: hash['provider'],
role_ids: role_ids,
role_ids: Role.signup_role_ids,
updated_by_id: 1,
created_by_id: 1,
)
}
if hash['info']['first_name'].present? && hash['info']['last_name'].present?
data[:firstname] = hash['info']['first_name']
data[:lastname] = hash['info']['last_name']
end
create!(data)
rescue => e
logger.error e
raise Exceptions::UnprocessableEntity, e.message

0 comments on commit 6439203

Please sign in to comment.