Usage of confirm_within was deprecated in favor allow_unconfirmed_access_for

This commit is contained in:
José Valim 2011-12-11 20:18:02 +01:00
parent d952dea32b
commit 930b324c15
12 changed files with 41 additions and 35 deletions

View File

@ -6,15 +6,17 @@
* deprecation
* Devise.apply_schema is deprecated
* Usage of rememberable with remember_token is deprecated
* Usage of recoverable without reset_password_sent_at is deprecated
* Usage of remember_across_browsers is deprecated
* Usage of remember_across_browsers was deprecated
* Usage of confirm_within was deprecated in favor allow_unconfirmed_access_for
* Usage of rememberable with remember_token was removed
* Usage of recoverable without reset_password_sent_at was removed
* Usage of case_insensitive_keys equals to false was removed
== 1.5.2
* enhancements
* Add support for Rails 3.1 new mass assignment conventions (by github.com/kirs)
* Add timeout_in method to Timeoutable, it can be overriden in a model (by github.com/lest)
* Add timeout_in method to Timeoutable, it can be overridden in a model (by github.com/lest)
* bug fix
* OmniAuth error message now shows the proper option (:strategy_class instead of :klass)

View File

@ -125,8 +125,8 @@ module Devise
@@extend_remember_period = false
# Time interval you can access your account before confirming your account.
mattr_accessor :confirm_within
@@confirm_within = 0.days
mattr_accessor :allow_unconfirmed_access_for
@@allow_unconfirmed_access_for = 0.days
# Defines which key will be used when confirming an account.
mattr_accessor :confirmation_keys
@ -230,6 +230,10 @@ module Devise
puts "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it."
end
def self.confirm_within=(value)
puts "\n[DEVISE] Devise.confirm_within= is deprecated. Please set Devise.allow_unconfirmed_access_for= instead."
end
# PRIVATE CONFIGURATION
# Store scopes mappings.
@ -369,7 +373,7 @@ module Devise
# initialization.
#
# Devise.initialize do |config|
# config.confirm_within = 2.days
# config.allow_unconfirmed_access_for = 2.days
#
# config.warden do |manager|
# # Configure warden to use other strategies, like oauth.

View File

@ -9,11 +9,11 @@ module Devise
#
# Confirmable adds the following options to devise_for:
#
# * +confirm_within+: the time you want to allow the user to access his account
# * +allow_unconfirmed_access_for+: the time you want to allow the user to access his account
# before confirming it. After this period, the user access is denied. You can
# use this to let your user access some features of your application without
# confirming the account, but blocking it after a certain period (ie 7 days).
# By default confirm_within is zero, it means users always have to confirm to sign in.
# By default allow_unconfirmed_access_for is zero, it means users always have to confirm to sign in.
# * +reconfirmable+: requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field to be setup (t.reconfirmable in migrations). Until confirmed new email is
@ -117,20 +117,20 @@ module Devise
#
# Example:
#
# # confirm_within = 1.day and confirmation_sent_at = today
# # allow_unconfirmed_access_for = 1.day and confirmation_sent_at = today
# confirmation_period_valid? # returns true
#
# # confirm_within = 5.days and confirmation_sent_at = 4.days.ago
# # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 4.days.ago
# confirmation_period_valid? # returns true
#
# # confirm_within = 5.days and confirmation_sent_at = 5.days.ago
# # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 5.days.ago
# confirmation_period_valid? # returns false
#
# # confirm_within = 0.days
# # allow_unconfirmed_access_for = 0.days
# confirmation_period_valid? # will always return false
#
def confirmation_period_valid?
confirmation_sent_at && confirmation_sent_at.utc >= self.class.confirm_within.ago
confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago
end
# Checks whether the record is confirmed or not or a new email has been added, yielding to the block
@ -213,7 +213,7 @@ module Devise
find_or_initialize_with_errors(unconfirmed_required_attributes, unconfirmed_attributes, :not_found)
end
Devise::Models.config(self, :confirm_within, :confirmation_keys, :reconfirmable)
Devise::Models.config(self, :allow_unconfirmed_access_for, :confirmation_keys, :reconfirmable)
end
end
end

View File

@ -80,7 +80,7 @@ Devise.setup do |config|
# able to access the website for two days without confirming his account,
# access will be blocked just in the third day. Default is 0.days, meaning
# the user cannot access the website without confirming his account.
# config.confirm_within = 2.days
# config.allow_unconfirmed_access_for = 2.days
# If true, requires any email changes to be confirmed (exctly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email

View File

@ -12,8 +12,8 @@ end
class DeviseTest < ActiveSupport::TestCase
test 'model options can be configured through Devise' do
swap Devise, :confirm_within => 113, :pepper => "foo" do
assert_equal 113, Devise.confirm_within
swap Devise, :allow_unconfirmed_access_for => 113, :pepper => "foo" do
assert_equal 113, Devise.allow_unconfirmed_access_for
assert_equal "foo", Devise.pepper
end
end

View File

@ -98,7 +98,7 @@ class ConfirmationTest < ActionController::IntegrationTest
end
test 'not confirmed user with setup to block without confirmation should not be able to sign in' do
swap Devise, :confirm_within => 0.days do
swap Devise, :allow_unconfirmed_access_for => 0.days do
sign_in_as_user(:confirm => false)
assert_contain 'You have to confirm your account before continuing'
@ -107,7 +107,7 @@ class ConfirmationTest < ActionController::IntegrationTest
end
test 'not confirmed user should not see confirmation message if invalid credentials are given' do
swap Devise, :confirm_within => 0.days do
swap Devise, :allow_unconfirmed_access_for => 0.days do
sign_in_as_user(:confirm => false) do
fill_in 'password', :with => 'invalid'
end
@ -118,7 +118,7 @@ class ConfirmationTest < ActionController::IntegrationTest
end
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
swap Devise, :confirm_within => 1.day do
swap Devise, :allow_unconfirmed_access_for => 1.day do
sign_in_as_user(:confirm => false)
assert_response :success

View File

@ -63,7 +63,7 @@ class TrackableHooksTest < ActionController::IntegrationTest
end
test "does not update anything if user has signed out along the way" do
swap Devise, :confirm_within => 0 do
swap Devise, :allow_unconfirmed_access_for => 0 do
user = create_user(:confirm => false)
sign_in_as_user

View File

@ -164,19 +164,19 @@ class ConfirmableTest < ActiveSupport::TestCase
end
test 'confirm time should fallback to devise confirm in default configuration' do
swap Devise, :confirm_within => 1.day do
swap Devise, :allow_unconfirmed_access_for => 1.day do
user = new_user
user.confirmation_sent_at = 2.days.ago
assert_not user.active_for_authentication?
Devise.confirm_within = 3.days
Devise.allow_unconfirmed_access_for = 3.days
assert user.active_for_authentication?
end
end
test 'should be active when confirmation sent at is not overpast' do
swap Devise, :confirm_within => 5.days do
Devise.confirm_within = 5.days
swap Devise, :allow_unconfirmed_access_for => 5.days do
Devise.allow_unconfirmed_access_for = 5.days
user = create_user
user.confirmation_sent_at = 4.days.ago
@ -198,7 +198,7 @@ class ConfirmableTest < ActiveSupport::TestCase
end
test 'should not be active when confirm in is zero' do
Devise.confirm_within = 0.days
Devise.allow_unconfirmed_access_for = 0.days
user = create_user
user.confirmation_sent_at = Date.today
assert_not user.active_for_authentication?

View File

@ -2,7 +2,7 @@ require 'test_helper'
class Configurable < User
devise :database_authenticatable, :encryptable, :confirmable, :rememberable, :timeoutable, :lockable,
:stretches => 15, :pepper => 'abcdef', :confirm_within => 5.days,
:stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days,
:remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
end
@ -87,8 +87,8 @@ class ActiveRecordTest < ActiveSupport::TestCase
assert_equal 'abcdef', Configurable.pepper
end
test 'set a default value for confirm_within' do
assert_equal 5.days, Configurable.confirm_within
test 'set a default value for allow_unconfirmed_access_for' do
assert_equal 5.days, Configurable.allow_unconfirmed_access_for
end
test 'set a default value for remember_for' do

View File

@ -68,11 +68,11 @@ Devise.setup do |config|
# ==> Configuration for :confirmable
# The time you want to give your user to confirm his account. During this time
# he will be able to access your application without confirming. Default is nil.
# When confirm_within is zero, the user won't be able to sign in without confirming.
# When allow_unconfirmed_access_for is zero, the user won't be able to sign in without confirming.
# You can use this to let your user access some features of your application
# without confirming the account, but blocking it after a certain period
# (ie 2 days).
# config.confirm_within = 2.days
# config.allow_unconfirmed_access_for = 2.days
# Defines which key will be used when confirming an account
# config.confirmation_keys = [ :email ]

View File

@ -5,7 +5,7 @@ module SharedAdmin
devise :database_authenticatable, :encryptable, :registerable,
:timeoutable, :recoverable, :lockable, :confirmable,
:unlock_strategy => :time, :lock_strategy => :none,
:confirm_within => 2.weeks, :reconfirmable => true
:allow_unconfirmed_access_for => 2.weeks, :reconfirmable => true
validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed?
end

View File

@ -17,7 +17,7 @@ class TestHelpersTest < ActionController::TestCase
end
test "redirects if attempting to access a page with an unconfirmed account" do
swap Devise, :confirm_within => 0 do
swap Devise, :allow_unconfirmed_access_for => 0 do
user = create_user
assert !user.active_for_authentication?
@ -28,7 +28,7 @@ class TestHelpersTest < ActionController::TestCase
end
test "returns nil if accessing current_user with an unconfirmed account" do
swap Devise, :confirm_within => 0 do
swap Devise, :allow_unconfirmed_access_for => 0 do
user = create_user
assert !user.active_for_authentication?