allow_unconfirmed_access_for set to nil means unconfirmed access for unlimited time

closes #2275
This commit is contained in:
Vasiliy Ermolovich 2013-02-13 21:12:47 +03:00
parent 1b2460171e
commit 395a69b4ef
4 changed files with 15 additions and 1 deletions

View File

@ -1,5 +1,8 @@
== master
* enhancements
* allow_unconfirmed_access_for config from `:confirmable` module can be set to `nil` that means unconfirmed access for unlimited time. (by @nashby)
* bug fix
* Generating scoped devise views now uses the correct scoped shared links partial instead of the default devise one (by @nashby)
* Fix inheriting mailer templates from `Devise::Mailer`

View File

@ -102,6 +102,7 @@ module Devise
@@extend_remember_period = false
# Time interval you can access your account before confirming your account.
# nil - allows unconfirmed access for unlimited time
mattr_accessor :allow_unconfirmed_access_for
@@allow_unconfirmed_access_for = 0.days

View File

@ -158,8 +158,11 @@ module Devise
# # allow_unconfirmed_access_for = 0.days
# confirmation_period_valid? # will always return false
#
# # allow_unconfirmed_access_for = nil
# confirmation_period_valid? # will always return true
#
def confirmation_period_valid?
confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago
self.class.allow_unconfirmed_access_for.nil? || (confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago)
end
# Checks if the user confirmation happens before the token becomes invalid

View File

@ -204,6 +204,13 @@ class ConfirmableTest < ActiveSupport::TestCase
assert_not user.active_for_authentication?
end
test 'should be active when we set allow_unconfirmed_access_for to nil' do
Devise.allow_unconfirmed_access_for = nil
user = create_user
user.confirmation_sent_at = Date.today
assert user.active_for_authentication?
end
test 'should not be active without confirmation' do
user = create_user
user.confirmation_sent_at = nil