Simplify active_for_authentication? checking.

This commit is contained in:
José Valim 2011-11-05 19:54:40 -02:00
parent a816e538ab
commit 0439c35198
2 changed files with 5 additions and 13 deletions

View File

@ -27,7 +27,7 @@ module Devise
#
# == active_for_authentication?
#
# Before authenticating a user and in each request, Devise checks if your model is active by
# After authenticating a user and in each request, Devise checks if your model is active by
# calling model.active_for_authentication?. This method is overwriten by other devise modules. For instance,
# :confirmable overwrites .active_for_authentication? to only return true if your model was confirmed.
#
@ -61,12 +61,7 @@ module Devise
# However, you should not overwrite this method, you should overwrite active_for_authentication?
# and inactive_message instead.
def valid_for_authentication?
authenticated = block_given? ? yield : true
if authenticated
active_for_authentication? || inactive_message
else
authenticated
end
block_given? ? yield : true
end
def active_for_authentication?

View File

@ -79,12 +79,10 @@ module Devise
# if the user can login or not (wrong password, etc)
unlock_access! if lock_expired?
case (result = super)
when Symbol
return result
when TrueClass
if super
self.failed_attempts = 0
save(:validate => false)
true
else
self.failed_attempts ||= 0
self.failed_attempts += 1
@ -94,9 +92,8 @@ module Devise
else
save(:validate => false)
end
false
end
result
end
protected