Browse Source

merge rud's: Chore/extract reused hash key

master
Dmitrii Golub 11 years ago
parent
commit
3470a57fd1
  1. 2
      app/controllers/devise/two_factor_authentication_controller.rb
  2. 2
      lib/two_factor_authentication.rb
  3. 4
      lib/two_factor_authentication/controllers/helpers.rb
  4. 2
      lib/two_factor_authentication/hooks/two_factor_authenticatable.rb

2
app/controllers/devise/two_factor_authentication_controller.rb

@ -9,7 +9,7 @@ class Devise::TwoFactorAuthenticationController < DeviseController
render :show and return if params[:code].nil? render :show and return if params[:code].nil?
if resource.authenticate_otp(params[:code]) 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 sign_in resource_name, resource, :bypass => true
set_flash_message :notice, :success set_flash_message :notice, :success
redirect_to stored_location_for(resource_name) || :root redirect_to stored_location_for(resource_name) || :root

2
lib/two_factor_authentication.rb

@ -16,6 +16,8 @@ module Devise
end end
module TwoFactorAuthentication module TwoFactorAuthentication
NEED_AUTHENTICATION = 'need_two_factor_authentication'
autoload :Schema, 'two_factor_authentication/schema' autoload :Schema, 'two_factor_authentication/schema'
module Controllers module Controllers
autoload :Helpers, 'two_factor_authentication/controllers/helpers' autoload :Helpers, 'two_factor_authentication/controllers/helpers'

4
lib/two_factor_authentication/controllers/helpers.rb

@ -12,7 +12,7 @@ module TwoFactorAuthentication
def handle_two_factor_authentication def handle_two_factor_authentication
unless devise_controller? unless devise_controller?
Devise.mappings.keys.flatten.any? do |scope| 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) handle_failed_second_factor(scope)
end end
end end
@ -42,7 +42,7 @@ module Devise
module Controllers module Controllers
module Helpers module Helpers
def is_fully_authenticated? 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 end
end end

2
lib/two_factor_authentication/hooks/two_factor_authenticatable.rb

@ -1,6 +1,6 @@
Warden::Manager.after_authentication do |user, auth, options| Warden::Manager.after_authentication do |user, auth, options|
if user.respond_to?(:need_two_factor_authentication?) 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 user.send_two_factor_authentication_code
end end
end end

Loading…
Cancel
Save