mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Migrate Github authentication to ManagedAuthenticator (#11170)
This commit adds an additional find_user_by_email hook to ManagedAuthenticator so that GitHub login can continue to support secondary email addresses
The github_user_infos table will be dropped in a follow-up commit.
This is the last core authenticator to be migrated to ManagedAuthenticator 🎉
This commit is contained in:
@@ -53,10 +53,9 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
|
||||
end
|
||||
|
||||
# Matching an account by email
|
||||
if primary_email_verified?(auth_token) &&
|
||||
match_by_email &&
|
||||
if match_by_email &&
|
||||
association.user.nil? &&
|
||||
(user = User.find_by_email(auth_token.dig(:info, :email)))
|
||||
(user = find_user_by_email(auth_token))
|
||||
|
||||
UserAssociatedAccount.where(user: user, provider_name: auth_token[:provider]).destroy_all # Destroy existing associations for the new user
|
||||
association.user = user
|
||||
@@ -118,6 +117,13 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
|
||||
retrieve_profile(user, association.info)
|
||||
end
|
||||
|
||||
def find_user_by_email(auth_token)
|
||||
email = auth_token.dig(:info, :email)
|
||||
if email && primary_email_verified?(auth_token)
|
||||
User.find_by_email(email)
|
||||
end
|
||||
end
|
||||
|
||||
def retrieve_avatar(user, url)
|
||||
return unless user && url
|
||||
return if user.user_avatar.try(:custom_upload_id).present?
|
||||
|
||||
Reference in New Issue
Block a user