diff --git a/app/controllers/devise/two_factor_authentication_controller.rb b/app/controllers/devise/two_factor_authentication_controller.rb index 1f2ac65..e302e01 100644 --- a/app/controllers/devise/two_factor_authentication_controller.rb +++ b/app/controllers/devise/two_factor_authentication_controller.rb @@ -9,7 +9,7 @@ class Devise::TwoFactorAuthenticationController < DeviseController render :show and return if params[:code].nil? if resource.authenticate_otp(params[:code]) - warden.session(resource_name)[:need_two_factor_authentication] = false + warden.session(resource_name)[TwoFactorAuthentication::NEED_AUTHENTICATION] = false sign_in resource_name, resource, :bypass => true set_flash_message :notice, :success redirect_to stored_location_for(resource_name) || :root diff --git a/lib/two_factor_authentication.rb b/lib/two_factor_authentication.rb index 3e6e67e..0d985ac 100644 --- a/lib/two_factor_authentication.rb +++ b/lib/two_factor_authentication.rb @@ -16,6 +16,8 @@ module Devise end module TwoFactorAuthentication + NEED_AUTHENTICATION = 'need_two_factor_authentication' + autoload :Schema, 'two_factor_authentication/schema' module Controllers autoload :Helpers, 'two_factor_authentication/controllers/helpers' diff --git a/lib/two_factor_authentication/controllers/helpers.rb b/lib/two_factor_authentication/controllers/helpers.rb index ef38330..5c151b2 100644 --- a/lib/two_factor_authentication/controllers/helpers.rb +++ b/lib/two_factor_authentication/controllers/helpers.rb @@ -12,7 +12,7 @@ module TwoFactorAuthentication def handle_two_factor_authentication unless devise_controller? Devise.mappings.keys.flatten.any? do |scope| - if signed_in?(scope) and warden.session(scope)[:need_two_factor_authentication] + if signed_in?(scope) and warden.session(scope)[TwoFactorAuthentication::NEED_AUTHENTICATION] handle_failed_second_factor(scope) end end @@ -42,7 +42,9 @@ module Devise module Controllers module Helpers def is_fully_authenticated? - !session["warden.user.user.session"].try(:[], :need_two_factor_authentication) + !session["warden.user.user.session"].try(:[], + TwoFactorAuthentication::NEED_AUTHENTICATION + ) end end end diff --git a/lib/two_factor_authentication/hooks/two_factor_authenticatable.rb b/lib/two_factor_authentication/hooks/two_factor_authenticatable.rb index 2abb4a4..985dc34 100644 --- a/lib/two_factor_authentication/hooks/two_factor_authenticatable.rb +++ b/lib/two_factor_authentication/hooks/two_factor_authenticatable.rb @@ -1,6 +1,6 @@ Warden::Manager.after_authentication do |user, auth, options| if user.respond_to?(:need_two_factor_authentication?) - if auth.session(options[:scope])[:need_two_factor_authentication] = user.need_two_factor_authentication?(auth.request) + if auth.session(options[:scope])[TwoFactorAuthentication::NEED_AUTHENTICATION] = user.need_two_factor_authentication?(auth.request) user.send_two_factor_authentication_code end end