Class: UserAuthenticator
- Inherits:
-
Object
- Object
- UserAuthenticator
- Defined in:
- app/services/user_authenticator.rb
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #email_valid? ⇒ Boolean
- #finish ⇒ Object
- #has_authenticator? ⇒ Boolean
-
#initialize(user, session, authenticator_finder: Users::OmniauthCallbacksController, require_password: true) ⇒ UserAuthenticator
constructor
A new instance of UserAuthenticator.
- #start ⇒ Object
Constructor Details
#initialize(user, session, authenticator_finder: Users::OmniauthCallbacksController, require_password: true) ⇒ UserAuthenticator
Returns a new instance of UserAuthenticator.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/services/user_authenticator.rb', line 4 def initialize( user, session, authenticator_finder: Users::OmniauthCallbacksController, require_password: true ) @user = user @session = session if session&.dig(:authentication) && session[:authentication].is_a?(Hash) @auth_result = Auth::Result.from_session_data(session[:authentication], user: user) end @authenticator_finder = authenticator_finder @require_password = require_password end |
Instance Method Details
#authenticated? ⇒ Boolean
49 50 51 52 53 54 |
# File 'app/services/user_authenticator.rb', line 49 def authenticated? return false if !@auth_result return false if @auth_result&.email&.downcase != @user.email.downcase return false if !@auth_result.email_valid true end |
#email_valid? ⇒ Boolean
45 46 47 |
# File 'app/services/user_authenticator.rb', line 45 def email_valid? @auth_result&.email_valid end |
#finish ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/user_authenticator.rb', line 34 def finish if authenticator authenticator.after_create_account(@user, @auth_result) confirm_email end if @session&.dig(:authentication) @session[:authentication] = @auth_result = nil @session[:authenticated_with_oauth] = true end end |
#has_authenticator? ⇒ Boolean
30 31 32 |
# File 'app/services/user_authenticator.rb', line 30 def has_authenticator? !!authenticator end |
#start ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/user_authenticator.rb', line 19 def start if authenticated? @user.active = true @auth_result.apply_user_attributes! elsif @require_password @user.password_required! end @user.skip_email_validation = true if @auth_result && @auth_result.skip_email_validation end |