Browse Source

Merge branch 'checkdin-chore/extract-reused-hash-key'

master
Dmitrii Golub 11 years ago
parent
commit
aa110afd35
  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?
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

2
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'

4
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,7 @@ 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

2
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

Loading…
Cancel
Save