module Devision::Lockable

Public Class Methods

required_fields(klass) click to toggle source
# File lib/devision/models/lockable.rb, line 7
def self.required_fields(klass)
  attributes = []
  attributes << :failed_attempts if klass.lock_strategy_enabled?(:failed_attempts)
  attributes << :locked_at if klass.unlock_strategy_enabled?(:time)
  attributes << :unlock_token if klass.unlock_strategy_enabled?(:email)
  attributes
end

Public Instance Methods

access_locked?() click to toggle source
# File lib/devision/models/lockable.rb, line 27
def access_locked?
  !!locked_at && !lock_expired?
end
lock_access!() click to toggle source
# File lib/devision/models/lockable.rb, line 15
def lock_access!
  self.locked_at = Time.now.utc
  save(validate: false)
end
unlock_access!() click to toggle source
# File lib/devision/models/lockable.rb, line 20
def unlock_access!
  self.locked_at = nil
  self.failed_attempts = 0 if respond_to?(:failed_attempts=)
  self.unlock_token = nil if respond_to?(:unlock_token=)
  save(validate: false)
end

Protected Instance Methods

attempts_exceeded?() click to toggle source
# File lib/devision/models/lockable.rb, line 32
def attempts_exceeded?
  self.failed_attempts >= self.class.maximum_attempts
end
last_attempt?() click to toggle source
# File lib/devision/models/lockable.rb, line 36
def last_attempt?
  self.failed_attempts == (self.class.maximum_attempts - 1)
end
lock_expired?() click to toggle source
# File lib/devision/models/lockable.rb, line 40
def lock_expired?
  if unlock_strategy_enabled?(:time)
    locked_at && locked_at < self.class.unlock_in.ago
  else
    false
  end
end