mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Introduce Auth::Result API for overrides_* (#15378)
This allows authenticators to instruct the Auth::Result to override attributes without using the general site settings. This provides an easy migration path for auth plugins which offer their own "overrides email", "overrides username" or "overrides name" settings. With this new api, they can set `overrides_*` on the result object, and the attribute will be overriden regardless of the general site setting. ManagedAuthenticator is updated to use this new API. Plugins which consume ManagedAuthenticator will instantly take advantage of this change.
This commit is contained in:
@ -77,17 +77,6 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
|
||||
# Save to the DB. Do this even if we don't have a user - it might be linked up later in after_create_account
|
||||
association.save!
|
||||
|
||||
# Update the user's email address from the auth payload
|
||||
if association.user &&
|
||||
(always_update_user_email? || association.user.email.end_with?(".invalid")) &&
|
||||
primary_email_verified?(auth_token) &&
|
||||
(email = auth_token.dig(:info, :email)) &&
|
||||
(email != association.user.email) &&
|
||||
!User.find_by_email(email)
|
||||
|
||||
association.user.update!(email: email)
|
||||
end
|
||||
|
||||
# Update avatar/profile
|
||||
retrieve_avatar(association.user, association.info["image"])
|
||||
retrieve_profile(association.user, association.info)
|
||||
@ -104,6 +93,7 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
|
||||
end
|
||||
result.username = info[:nickname]
|
||||
result.email_valid = primary_email_verified?(auth_token) if result.email.present?
|
||||
result.overrides_email = always_update_user_email?
|
||||
result.extra_data = {
|
||||
provider: auth_token[:provider],
|
||||
uid: auth_token[:uid]
|
||||
|
Reference in New Issue
Block a user