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:
parent
d23a7ca8d5
commit
ed51fc7636
6 changed files with 29 additions and 15 deletions
|
@ -1,5 +1,6 @@
|
|||
* enhancements
|
||||
* 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
|
||||
* Fix a bug where configuration options were being included too late
|
||||
|
|
|
@ -173,7 +173,7 @@ module Devise
|
|||
|
||||
# Time interval you can reset your password with a reset password key
|
||||
mattr_accessor :reset_password_within
|
||||
@@reset_password_within = 1.hour
|
||||
@@reset_password_within = nil
|
||||
|
||||
# The default scope which is used by warden.
|
||||
mattr_accessor :default_scope
|
||||
|
|
|
@ -35,7 +35,7 @@ module Devise
|
|||
|
||||
# Resets reset password token and send reset password instructions by email
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -59,15 +59,20 @@ module Devise
|
|||
# reset_password_period_valid? # will always return false
|
||||
#
|
||||
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
|
||||
|
||||
protected
|
||||
|
||||
def should_generate_token?
|
||||
reset_password_token.nil? || !reset_password_period_valid?
|
||||
end
|
||||
|
||||
# Generates a new random token for reset password
|
||||
def generate_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
|
||||
|
||||
# Resets the reset password token with and save the record without
|
||||
|
@ -79,7 +84,7 @@ module Devise
|
|||
# Removes reset_password token
|
||||
def clear_reset_password_token
|
||||
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
|
||||
|
||||
module ClassMethods
|
||||
|
@ -115,8 +120,7 @@ module Devise
|
|||
recoverable
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :reset_password_keys)
|
||||
Devise::Models.config(self, :reset_password_within)
|
||||
Devise::Models.config(self, :reset_password_keys, :reset_password_within)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ module Devise
|
|||
def database_authenticatable(options={})
|
||||
null = options[: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 :encrypted_password, String, :null => null, :default => default, :limit => 128
|
||||
|
@ -39,9 +39,13 @@ module Devise
|
|||
end
|
||||
|
||||
# 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_sent_at, DateTime
|
||||
apply_devise_schema :reset_password_sent_at, DateTime if use_within
|
||||
end
|
||||
|
||||
# Creates remember_token and remember_created_at.
|
||||
|
|
|
@ -125,11 +125,11 @@ Devise.setup do |config|
|
|||
#
|
||||
# Defines which key will be used when recovering the password for an account
|
||||
# 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
|
||||
# Default to 1 hour
|
||||
config.reset_password_within = 1.hour
|
||||
|
||||
# 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
|
||||
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
||||
|
|
|
@ -119,6 +119,11 @@ Devise.setup do |config|
|
|||
# Defines which key will be used when recovering the password for an account
|
||||
# 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
|
||||
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
||||
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
||||
|
|
Loading…
Reference in a new issue