DEV: Add profile fetching support to ManagedAuthenticator

This commit is contained in:
David Taylor
2018-12-07 14:04:21 +00:00
parent f7ce607e5d
commit 3cad3f9df1
2 changed files with 53 additions and 0 deletions

View File

@ -73,6 +73,7 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
extra: auth_token[:extra] || {}
)
retrieve_avatar(result.user, auth_token.dig(:info, :image))
retrieve_profile(result.user, auth_token[:info])
end
result.email_valid = true if result.email
@ -95,6 +96,7 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
data = auth[:extra_data]
create_association!(data.merge(user: user))
retrieve_avatar(user, data.dig(:info, :image))
retrieve_profile(user, data[:info])
end
def retrieve_avatar(user, url)
@ -102,4 +104,18 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
return if user.user_avatar.try(:custom_upload_id).present?
Jobs.enqueue(:download_avatar_from_url, url: url, user_id: user.id, override_gravatar: false)
end
def retrieve_profile(user, info)
return unless user
bio = info[:description]
location = info[:location]
if bio || location
profile = user.user_profile
profile.bio_raw = bio unless profile.bio_raw.present?
profile.location = location unless profile.location.present?
profile.save
end
end
end