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

Tidy up previous commits.

This commit is contained in:
José Valim 2011-03-30 15:35:38 +02:00
parent d23a7ca8d5
commit ed51fc7636
6 changed files with 29 additions and 15 deletions

View file

@ -1,5 +1,6 @@
* enhancements * enhancements
* All controllers can now handle different mime types than html using Responders (by github.com/sikachu) * All controllers can now handle different mime types than html using Responders (by github.com/sikachu)
* Added reset_password_within as configuration option to send the token for recovery (by github.com/jdguyot)
* bug fix * bug fix
* Fix a bug where configuration options were being included too late * Fix a bug where configuration options were being included too late

View file

@ -173,7 +173,7 @@ module Devise
# Time interval you can reset your password with a reset password key # Time interval you can reset your password with a reset password key
mattr_accessor :reset_password_within mattr_accessor :reset_password_within
@@reset_password_within = 1.hour @@reset_password_within = nil
# The default scope which is used by warden. # The default scope which is used by warden.
mattr_accessor :default_scope mattr_accessor :default_scope

View file

@ -35,7 +35,7 @@ module Devise
# Resets reset password token and send reset password instructions by email # Resets reset password token and send reset password instructions by email
def send_reset_password_instructions def send_reset_password_instructions
generate_reset_password_token! if self.reset_password_token.nil? or !reset_password_period_valid? generate_reset_password_token! if should_generate_token?
::Devise.mailer.reset_password_instructions(self).deliver ::Devise.mailer.reset_password_instructions(self).deliver
end end
@ -59,15 +59,20 @@ module Devise
# reset_password_period_valid? # will always return false # reset_password_period_valid? # will always return false
# #
def reset_password_period_valid? def reset_password_period_valid?
reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago respond_to?(:reset_password_sent_at) && reset_password_sent_at &&
reset_password_sent_at.utc >= self.class.reset_password_within.ago
end end
protected protected
def should_generate_token?
reset_password_token.nil? || !reset_password_period_valid?
end
# Generates a new random token for reset password # Generates a new random token for reset password
def generate_reset_password_token def generate_reset_password_token
self.reset_password_token = self.class.reset_password_token self.reset_password_token = self.class.reset_password_token
self.reset_password_sent_at = Time.now.utc self.reset_password_sent_at = Time.now.utc if respond_to?(:reset_password_sent_at=)
end end
# Resets the reset password token with and save the record without # Resets the reset password token with and save the record without
@ -79,7 +84,7 @@ module Devise
# Removes reset_password token # Removes reset_password token
def clear_reset_password_token def clear_reset_password_token
self.reset_password_token = nil self.reset_password_token = nil
self.reset_password_sent_at = nil self.reset_password_sent_at = nil if respond_to?(:reset_password_sent_at=)
end end
module ClassMethods module ClassMethods
@ -115,8 +120,7 @@ module Devise
recoverable recoverable
end end
Devise::Models.config(self, :reset_password_keys) Devise::Models.config(self, :reset_password_keys, :reset_password_within)
Devise::Models.config(self, :reset_password_within)
end end
end end
end end

View file

@ -15,7 +15,7 @@ module Devise
def database_authenticatable(options={}) def database_authenticatable(options={})
null = options[:null] || false null = options[:null] || false
default = options.key?(:default) ? options[:default] : ("" if null == false) default = options.key?(:default) ? options[:default] : ("" if null == false)
include_email = !self.respond_to?(:authentication_keys) || self.authentication_keys.include?(:email) include_email = !respond_to?(:authentication_keys) || self.authentication_keys.include?(:email)
apply_devise_schema :email, String, :null => null, :default => default if include_email apply_devise_schema :email, String, :null => null, :default => default if include_email
apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128 apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128
@ -39,9 +39,13 @@ module Devise
end end
# Creates reset_password_token and reset_password_sent_at. # Creates reset_password_token and reset_password_sent_at.
def recoverable #
# == Options
# * :reset_within - When true, adds a column that reset passwords within some date
def recoverable(options={})
use_within = options.fetch(:reset_within, Devise.reset_password_within.present?)
apply_devise_schema :reset_password_token, String apply_devise_schema :reset_password_token, String
apply_devise_schema :reset_password_sent_at, DateTime apply_devise_schema :reset_password_sent_at, DateTime if use_within
end end
# Creates remember_token and remember_created_at. # Creates remember_token and remember_created_at.

View file

@ -125,11 +125,11 @@ Devise.setup do |config|
# #
# Defines which key will be used when recovering the password for an account # Defines which key will be used when recovering the password for an account
# config.reset_password_keys = [ :email ] # config.reset_password_keys = [ :email ]
#
# Time interval you can reset your password with a reset password key # Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to change their passwords # Don't put a too small interval or your users won't have the time to
# Default to 1 hour # change their passwords.
config.reset_password_within = 1.hour config.reset_password_within = 2.hours
# ==> Configuration for :encryptable # ==> Configuration for :encryptable
# Allow you to use another encryption algorithm besides bcrypt (default). You can use # Allow you to use another encryption algorithm besides bcrypt (default). You can use

View file

@ -119,6 +119,11 @@ Devise.setup do |config|
# Defines which key will be used when recovering the password for an account # Defines which key will be used when recovering the password for an account
# config.reset_password_keys = [ :email ] # config.reset_password_keys = [ :email ]
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to
# change their passwords.
config.reset_password_within = 2.hours
# ==> Configuration for :encryptable # ==> Configuration for :encryptable
# Allow you to use another encryption algorithm besides bcrypt (default). You can use # Allow you to use another encryption algorithm besides bcrypt (default). You can use
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,