1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Bring Devise::ALL back to modules and improving lockable docs.

This commit is contained in:
Carlos Antonio da Silva 2010-01-24 21:22:45 -02:00
parent 21359fb433
commit 658059f31a
4 changed files with 22 additions and 8 deletions

View file

@ -59,7 +59,7 @@ module Devise
raise "You need to give at least one Devise module" if modules.empty?
options = modules.extract_options!
@devise_modules = modules.map(&:to_sym).uniq
@devise_modules = Devise::ALL & modules.map(&:to_sym).uniq
Devise.orm_class.included_modules_hook(self) do
devise_modules.each do |m|

View file

@ -3,6 +3,20 @@ 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).
# It's also possible to setup lockable to use both email and time strategies.
#
# Configuration:
#
# maximum_attempts: how many attempts should be accepted before blocking the user.
# unlock_strategy: unlock the user account by :time, :email or :both.
# 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
include Devise::Models::Activatable
@ -21,13 +35,13 @@ module Devise
end
end
# calls lock and save the model
# Lock an user also saving the record.
def lock!
lock
save(false)
end
# Unlock an user by cleaning locket_at and failed_attempts
# Unlock an user by cleaning locket_at and failed_attempts.
def unlock!
if_locked do
self.locked_at = nil
@ -37,7 +51,7 @@ module Devise
end
end
# Verifies whether a user is locked or not
# Verifies whether a user is locked or not.
def locked?
locked_at && !lock_expired?
end
@ -47,7 +61,7 @@ module Devise
::DeviseMailer.deliver_unlock_instructions(self)
end
# Resend the unlock instructions if the user is locked
# Resend the unlock instructions if the user is locked.
def resend_unlock!
if_locked do
generate_unlock_token unless unlock_token.present?
@ -113,7 +127,7 @@ module Devise
end
end
# Is the unlock enabled for the given unlock option?
# Is the unlock enabled for the given unlock strategy?
def unlock_strategy_enabled?(strategy)
[:both, strategy].include?(self.class.unlock_strategy)
end

View file

@ -1,7 +1,7 @@
module Devise
module Models
# Registerable is responsible for everything related to registering a new
# resource (ie account or sign up).
# resource (ie user sign up).
module Registerable
end
end

View file

@ -9,7 +9,7 @@ module Devise
#
# Configuration:
#
# timeout: the time you want to timeout the user session without activity.
# timeout_in: the time you want to timeout the user session without activity.
module Timeoutable
def self.included(base)
base.extend ClassMethods