mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Refactor Auth::Result for readability, recreate during signup flow
This commit is contained in:
@@ -5,7 +5,9 @@ class UserAuthenticator
|
||||
def initialize(user, session, authenticator_finder = Users::OmniauthCallbacksController)
|
||||
@user = user
|
||||
@session = session
|
||||
@auth_session = session[:authentication]
|
||||
if session[:authentication] && session[:authentication].is_a?(Hash)
|
||||
@auth_result = Auth::Result.from_session_data(session[:authentication])
|
||||
end
|
||||
@authenticator_finder = authenticator_finder
|
||||
end
|
||||
|
||||
@@ -16,7 +18,7 @@ class UserAuthenticator
|
||||
@user.password_required!
|
||||
end
|
||||
|
||||
@user.skip_email_validation = true if @auth_session && @auth_session[:skip_email_validation].present?
|
||||
@user.skip_email_validation = true if @auth_result && @auth_result.skip_email_validation
|
||||
end
|
||||
|
||||
def has_authenticator?
|
||||
@@ -25,18 +27,18 @@ class UserAuthenticator
|
||||
|
||||
def finish
|
||||
if authenticator
|
||||
authenticator.after_create_account(@user, @auth_session)
|
||||
authenticator.after_create_account(@user, @auth_result)
|
||||
confirm_email
|
||||
end
|
||||
@session[:authentication] = @auth_session = nil if @auth_session
|
||||
@session[:authentication] = @auth_result = nil if @session[:authentication]
|
||||
end
|
||||
|
||||
def email_valid?
|
||||
@auth_session && @auth_session[:email_valid]
|
||||
@auth_result&.email_valid
|
||||
end
|
||||
|
||||
def authenticated?
|
||||
@auth_session && @auth_session[:email]&.downcase == @user.email.downcase && @auth_session[:email_valid].to_s == "true"
|
||||
@auth_result && @auth_result.email.downcase == @user.email.downcase && @auth_result.email_valid.to_s == "true"
|
||||
end
|
||||
|
||||
private
|
||||
@@ -55,7 +57,7 @@ class UserAuthenticator
|
||||
end
|
||||
|
||||
def authenticator_name
|
||||
@auth_session && @auth_session[:authenticator_name]
|
||||
@auth_result&.authenticator_name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user