From 395a69b4efd1fb57e94fea16bd3cb77180d3ae57 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Wed, 13 Feb 2013 21:12:47 +0300 Subject: [PATCH] allow_unconfirmed_access_for set to nil means unconfirmed access for unlimited time closes #2275 --- CHANGELOG.rdoc | 3 +++ lib/devise.rb | 1 + lib/devise/models/confirmable.rb | 5 ++++- test/models/confirmable_test.rb | 7 +++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 3193998aff..10048dfef0 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -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` diff --git a/lib/devise.rb b/lib/devise.rb index a6ed19a592..0d5ad7be71 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -102,6 +102,7 @@ module Strategies @@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 diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index b3b4188db7..18146fd72c 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -158,8 +158,11 @@ def confirmation_required? # # 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 diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index 74df0b3769..d262b870af 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -204,6 +204,13 @@ def setup 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