2013-11-12 16:37:38 -06:00
|
|
|
class UserAuthenticator
|
2014-11-17 05:04:29 -06:00
|
|
|
|
2013-11-12 16:37:38 -06:00
|
|
|
def initialize(user, session, authenticator_finder = Users::OmniauthCallbacksController)
|
|
|
|
@user = user
|
|
|
|
@session = session[:authentication]
|
|
|
|
@authenticator_finder = authenticator_finder
|
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
|
|
|
if authenticated?
|
|
|
|
@user.active = true
|
|
|
|
else
|
|
|
|
@user.password_required!
|
|
|
|
end
|
2016-09-07 13:05:46 -05:00
|
|
|
|
|
|
|
@user.skip_email_validation = true if @session && @session[:skip_email_validation].present?
|
2013-11-12 16:37:38 -06:00
|
|
|
end
|
|
|
|
|
2014-03-19 22:49:25 -05:00
|
|
|
def has_authenticator?
|
|
|
|
!!authenticator
|
|
|
|
end
|
|
|
|
|
2013-11-12 16:37:38 -06:00
|
|
|
def finish
|
2017-02-28 20:16:26 -06:00
|
|
|
authenticator.after_create_account(@user, @session) if authenticator
|
2013-11-12 16:37:38 -06:00
|
|
|
@session = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def authenticated?
|
|
|
|
@session && @session[:email] == @user.email && @session[:email_valid]
|
|
|
|
end
|
|
|
|
|
|
|
|
def authenticator
|
|
|
|
if authenticator_name
|
|
|
|
@authenticator ||= @authenticator_finder.find_authenticator(authenticator_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def authenticator_name
|
|
|
|
@session && @session[:authenticator_name]
|
|
|
|
end
|
2014-11-17 05:04:29 -06:00
|
|
|
|
2013-11-12 16:37:38 -06:00
|
|
|
end
|