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

This commit is contained in:
Martin Edenhofer 2018-10-11 14:40:12 +02:00
parent 7dd6675552
commit 6439203900
3 changed files with 27 additions and 14 deletions

View file

@ -69,7 +69,7 @@ class SessionsController < ApplicationController
user_id = session[:user_id]
end
if !user_id
if !user_id || !User.exists?(user_id)
# get models
models = SessionHelper.models()

View file

@ -20,17 +20,25 @@ class Authorization < ApplicationModel
)
# 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 @@ class Authorization < ApplicationModel
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 file

@ -359,7 +359,6 @@ returns
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?
@ -367,19 +366,24 @@ returns
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