Files
discourse/app/services/user_authenticator.rb
T

43 lines
850 B
Ruby
Raw Normal View History

2013-11-12 14:37:38 -08:00
class UserAuthenticator
2013-11-12 14:37:38 -08: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
end
2014-03-20 14:49:25 +11:00
def has_authenticator?
!!authenticator
end
2013-11-12 14:37:38 -08:00
def finish
authenticator.after_create_account(@user, @session) if authenticator
2013-11-12 14:37:38 -08: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
2013-11-12 14:37:38 -08:00
end