Skip to content

Commit

Permalink
allow_unconfirmed_access_for set to nil means unconfirmed access for …
Browse files Browse the repository at this point in the history
…unlimited time

closes #2275
  • Loading branch information
nashby committed Feb 13, 2013
1 parent 1b24601 commit 395a69b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions 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`
Expand Down
1 change: 1 addition & 0 deletions lib/devise.rb
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion lib/devise/models/confirmable.rb
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/models/confirmable_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 395a69b

Please sign in to comment.