mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
refactoring attempts track to avoid saving the model twice
This commit is contained in:
parent
915afa5f0a
commit
827d0ce14c
1 changed files with 8 additions and 4 deletions
|
@ -14,12 +14,17 @@ module Devise
|
|||
end
|
||||
|
||||
# Lock an user setting it's locked_at to actual time.
|
||||
def lock!
|
||||
def lock
|
||||
self.locked_at = Time.now
|
||||
if [:both, :email].include?(self.class.unlock_strategy)
|
||||
generate_unlock_token
|
||||
self.send_unlock_instructions
|
||||
end
|
||||
end
|
||||
|
||||
# calls lock and save the model
|
||||
def lock!
|
||||
self.lock
|
||||
save(false)
|
||||
end
|
||||
|
||||
|
@ -64,12 +69,11 @@ module Devise
|
|||
def valid_for_authentication?(attributes)
|
||||
unless result = super
|
||||
self.failed_attempts += 1
|
||||
save(false)
|
||||
self.lock! if self.failed_attempts > self.class.maximum_attempts
|
||||
self.lock if self.failed_attempts > self.class.maximum_attempts
|
||||
else
|
||||
self.failed_attempts = 0
|
||||
save(false)
|
||||
end
|
||||
save(false) if changed?
|
||||
result
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue