mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
DEV: Add profile fetching support to ManagedAuthenticator
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user