From 365e01cbc71d0cce4cdb86dbe9a9fa4525052cc7 Mon Sep 17 00:00:00 2001 From: Julian Nadeau Date: Sun, 5 Jan 2020 01:40:10 -0500 Subject: [PATCH 1/2] Add Devise.available_router_name to support routing correctly with engines --- lib/two_factor_authentication/controllers/helpers.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/two_factor_authentication/controllers/helpers.rb b/lib/two_factor_authentication/controllers/helpers.rb index 64e8377c..4f10919b 100644 --- a/lib/two_factor_authentication/controllers/helpers.rb +++ b/lib/two_factor_authentication/controllers/helpers.rb @@ -35,8 +35,13 @@ def handle_failed_second_factor(scope) def two_factor_authentication_path_for(resource_or_scope = nil) scope = Devise::Mapping.find_scope!(resource_or_scope) + namespace = if Devise.available_router_name + send(Devise.available_router_name) + else + self + end change_path = "#{scope}_two_factor_authentication_path" - send(change_path) + namespace.send(change_path) end end From 4f6491ab6b36481e2f6cb9ebaa077b3c36db799d Mon Sep 17 00:00:00 2001 From: Julian Nadeau Date: Fri, 29 Jan 2021 12:36:39 -0500 Subject: [PATCH 2/2] replace update_attributes with update_columns --- .../models/two_factor_authenticatable.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/two_factor_authentication/models/two_factor_authenticatable.rb b/lib/two_factor_authentication/models/two_factor_authenticatable.rb index 6d73a0fb..68e4c21a 100644 --- a/lib/two_factor_authentication/models/two_factor_authenticatable.rb +++ b/lib/two_factor_authentication/models/two_factor_authenticatable.rb @@ -101,7 +101,7 @@ def generate_totp_secret def create_direct_otp(options = {}) # Create a new random OTP and store it in the database digits = options[:length] || self.class.direct_otp_length || 6 - update_attributes( + update_columns( direct_otp: random_base10(digits), direct_otp_sent_at: Time.now.utc ) @@ -122,7 +122,7 @@ def direct_otp_expired? end def clear_direct_otp - update_attributes(direct_otp: nil, direct_otp_sent_at: nil) + update_columns(direct_otp: nil, direct_otp_sent_at: nil) end end