Browse Source

Merge pull request #141 from rmm5t/delegate-send-new-otp-logic-to-user-model

Delegate logic of whether to send_new_otp to user#send_new_otp_after_login? method
master
Dmitrii Golub 7 years ago committed by GitHub
parent
commit
6e24299362
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      lib/two_factor_authentication/hooks/two_factor_authenticatable.rb
  2. 4
      lib/two_factor_authentication/models/two_factor_authenticatable.rb

2
lib/two_factor_authentication/hooks/two_factor_authenticatable.rb

@ -7,7 +7,7 @@ Warden::Manager.after_authentication do |user, auth, options|
if user.respond_to?(:need_two_factor_authentication?) && !bypass_by_cookie if user.respond_to?(:need_two_factor_authentication?) && !bypass_by_cookie
if auth.session(options[:scope])[TwoFactorAuthentication::NEED_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_new_otp unless user.totp_enabled? user.send_new_otp if user.send_new_otp_after_login?
end end
end end
end end

4
lib/two_factor_authentication/models/two_factor_authenticatable.rb

@ -62,6 +62,10 @@ module Devise
send_two_factor_authentication_code(direct_otp) send_two_factor_authentication_code(direct_otp)
end end
def send_new_otp_after_login?
!totp_enabled?
end
def send_two_factor_authentication_code(code) def send_two_factor_authentication_code(code)
raise NotImplementedError.new("No default implementation - please define in your class.") raise NotImplementedError.new("No default implementation - please define in your class.")
end end

Loading…
Cancel
Save