diff --git a/lib/devise.rb b/lib/devise.rb index 0451876df9..dcdacc151a 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -297,6 +297,9 @@ module Test mattr_accessor :sign_in_after_change_password @@sign_in_after_change_password = true + mattr_accessor :warden_hook_save_wrapper + @@warden_hook_save_wrapper = Proc.new { |hook| hook.call } + def self.activerecord51? # :nodoc: defined?(ActiveRecord) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x") end diff --git a/lib/devise/hooks/lockable.rb b/lib/devise/hooks/lockable.rb index a73a1752e2..fe964db951 100644 --- a/lib/devise/hooks/lockable.rb +++ b/lib/devise/hooks/lockable.rb @@ -5,8 +5,12 @@ Warden::Manager.after_set_user except: :fetch do |record, warden, options| if record.respond_to?(:failed_attempts) && warden.authenticated?(options[:scope]) unless record.failed_attempts.to_i.zero? - record.failed_attempts = 0 - record.save(validate: false) + wipe_attempts = Proc.new do + record.failed_attempts = 0 + record.save(validate: false) + end + + Devise.warden_hook_save_wrapper.call(wipe_attempts) end end end