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

Allow :unlock_strategy to be :none.

This commit is contained in:
José Valim 2010-03-30 00:07:11 +02:00
parent 7d14f0bbb9
commit 81926c2cd2
3 changed files with 26 additions and 16 deletions

View file

@ -14,6 +14,7 @@
* E-mails asks headers_for in the model to set the proper headers.
* Allow to specify haml in devise_views.
* Compatibility with Datamapper and Mongoid.
* Allow :unlock_strategy to be :none.
* bug fix
* Do not allow unlockable strategies based on time to access a controller.

View file

@ -13,7 +13,7 @@ module Devise
# 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_strategy: unlock the user account by :time, :email, :both or :none.
# unlock_in: the time you want to lock the user after to lock happens. Only
# available when unlock_strategy is :time or :both.
#
@ -34,12 +34,11 @@ module Devise
end
# Unlock an user by cleaning locket_at and failed_attempts.
# TODO Check if unlock_token is available.
def unlock_access!
if_access_locked do
self.locked_at = nil
self.failed_attempts = 0
self.unlock_token = nil
self.unlock_token = nil if self.respond_to?(:unlock_token=)
save(:validate => false)
end
end

View file

@ -12,37 +12,40 @@ module Devise
#
# == Options
# * :null - When true, allow columns to be null.
# * :encryptor - The encryptor going to be used, necessary for setting the proper encrypter password length.
# * :default - Should be set to "" when :null is true.
def database_authenticatable(options={})
null = options[:null] || false
default = options[:default]
encryptor = options[:encryptor] || (respond_to?(:encryptor) ? self.encryptor : :sha1)
null = options[:null] || false
default = options[:default]
if options.delete(:encryptor)
ActiveSupport::Deprecation.warn ":encryptor as option is deprecated, simply remove it."
end
apply_schema :email, String, :null => null, :default => default
apply_schema :encrypted_password, String, :null => null, :default => default, :limit => Devise::ENCRYPTORS_LENGTH[encryptor]
apply_schema :encrypted_password, String, :null => null, :default => default
apply_schema :password_salt, String, :null => null, :default => default
end
# Creates authentication_token.
def token_authenticatable
apply_schema :authentication_token, String, :limit => 20
def token_authenticatable(options={})
apply_schema :authentication_token, String
end
# Creates confirmation_token, confirmed_at and confirmation_sent_at.
def confirmable
apply_schema :confirmation_token, String, :limit => 20
apply_schema :confirmation_token, String
apply_schema :confirmed_at, DateTime
apply_schema :confirmation_sent_at, DateTime
end
# Creates reset_password_token.
def recoverable
apply_schema :reset_password_token, String, :limit => 20
apply_schema :reset_password_token, String
end
# Creates remember_token and remember_created_at.
def rememberable
apply_schema :remember_token, String, :limit => 20
apply_schema :remember_token, String
apply_schema :remember_created_at, DateTime
end
@ -56,10 +59,17 @@ module Devise
apply_schema :last_sign_in_ip, String
end
# Creates failed_attempts, unlock_token and locked_at
def lockable
# Creates failed_attempts, unlock_token and locked_at.
#
# == Options
# * :unlock_strategy - The strategy used for unlock. Can be :time, :email, :both, :none.
# If :email or :both, creates a unlock_token field.
def lockable(options={})
unlock_strategy = options[:unlock_strategy] ||
(respond_to?(:unlock_strategy) ? self.unlock_strategy : :both)
apply_schema :failed_attempts, Integer, :default => 0
apply_schema :unlock_token, String, :limit => 20
apply_schema :unlock_token, String if [:both, :email].include?(unlock_strategy)
apply_schema :locked_at, DateTime
end