lib/devise/models/lockable.rb in devise-1.1.rc0 vs lib/devise/models/lockable.rb in devise-1.1.rc1

- old
+ new

@@ -1,10 +1,7 @@ -require 'devise/models/activatable' - module Devise module Models - # Handles blocking a user access after a certain number of attempts. # Lockable accepts two different strategies to unlock a user after it's # blocked: email and time. The former will send an email to the user when # the lock happens, containing a link to unlock it's account. The second # will unlock the user automatically after some configured time (ie 2.hours). @@ -18,11 +15,10 @@ # unlock_in: the time you want to lock the user after to lock happens. Only # available when unlock_strategy is :time or :both. # module Lockable extend ActiveSupport::Concern - include Devise::Models::Activatable delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, :to => "self.class" # Lock an user setting it's locked_at to actual time. def lock_access! @@ -75,18 +71,18 @@ # Overwrites valid_for_authentication? from Devise::Models::Authenticatable # for verifying whether an user is allowed to sign in or not. If the user # is locked, it should never be allowed. def valid_for_authentication? - return :locked if access_locked? - return super unless persisted? - return super unless lock_strategy_enabled?(:failed_attempts) + return super unless persisted? && lock_strategy_enabled?(:failed_attempts) - if result = super + case (result = super) + when Symbol + return result + when TrueClass self.failed_attempts = 0 - else + when FalseClass self.failed_attempts += 1 - if attempts_exceeded? lock_access! return :locked end end