Fixed issue #2281 - O365/Office365 authentication missing given- and surname.
This commit is contained in:
parent
7dd6675552
commit
6439203900
3 changed files with 27 additions and 14 deletions
|
@ -69,7 +69,7 @@ class SessionsController < ApplicationController
|
||||||
user_id = session[:user_id]
|
user_id = session[:user_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
if !user_id
|
if !user_id || !User.exists?(user_id)
|
||||||
# get models
|
# get models
|
||||||
models = SessionHelper.models()
|
models = SessionHelper.models()
|
||||||
|
|
||||||
|
|
|
@ -20,17 +20,25 @@ class Authorization < ApplicationModel
|
||||||
)
|
)
|
||||||
|
|
||||||
# update username of auth entry if empty
|
# update username of auth entry if empty
|
||||||
if !auth.username && hash['info']['nickname']
|
if !auth.username && hash['info']['nickname'].present?
|
||||||
auth.update!(
|
auth.update!(
|
||||||
username: hash['info']['nickname'],
|
username: hash['info']['nickname'],
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# update image if needed
|
# update firstname/lastname if needed
|
||||||
if hash['info']['image']
|
|
||||||
user = User.find(auth.user_id)
|
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(
|
avatar = Avatar.add(
|
||||||
object: 'User',
|
object: 'User',
|
||||||
o_id: user.id,
|
o_id: user.id,
|
||||||
|
@ -40,13 +48,14 @@ class Authorization < ApplicationModel
|
||||||
updated_by_id: user.id,
|
updated_by_id: user.id,
|
||||||
created_by_id: user.id,
|
created_by_id: user.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
# update user link
|
|
||||||
if avatar && user.image != avatar.store_hash
|
if avatar && user.image != avatar.store_hash
|
||||||
user.image = avatar.store_hash
|
user.image = avatar.store_hash
|
||||||
user.save
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if user.changed?
|
||||||
|
user.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
auth
|
auth
|
||||||
end
|
end
|
||||||
|
|
|
@ -359,7 +359,6 @@ returns
|
||||||
|
|
||||||
def self.create_from_hash!(hash)
|
def self.create_from_hash!(hash)
|
||||||
|
|
||||||
role_ids = Role.signup_role_ids
|
|
||||||
url = ''
|
url = ''
|
||||||
hash['info']['urls']&.each_value do |local_url|
|
hash['info']['urls']&.each_value do |local_url|
|
||||||
next if local_url.blank?
|
next if local_url.blank?
|
||||||
|
@ -367,19 +366,24 @@ returns
|
||||||
url = local_url
|
url = local_url
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
create!(
|
data = {
|
||||||
login: hash['info']['nickname'] || hash['uid'],
|
login: hash['info']['nickname'] || hash['uid'],
|
||||||
firstname: hash['info']['name'],
|
firstname: hash['info']['name'] || hash['info']['display_name'],
|
||||||
email: hash['info']['email'],
|
email: hash['info']['email'],
|
||||||
image_source: hash['info']['image'],
|
image_source: hash['info']['image'],
|
||||||
web: url,
|
web: url,
|
||||||
address: hash['info']['location'],
|
address: hash['info']['location'],
|
||||||
note: hash['info']['description'],
|
note: hash['info']['description'],
|
||||||
source: hash['provider'],
|
source: hash['provider'],
|
||||||
role_ids: role_ids,
|
role_ids: Role.signup_role_ids,
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_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
|
rescue => e
|
||||||
logger.error e
|
logger.error e
|
||||||
raise Exceptions::UnprocessableEntity, e.message
|
raise Exceptions::UnprocessableEntity, e.message
|
||||||
|
|
Loading…
Reference in a new issue