mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Renamed confirm_in to confirm_within.
This commit is contained in:
parent
04b0622999
commit
3209e7d988
7 changed files with 49 additions and 40 deletions
|
@ -1,3 +1,6 @@
|
|||
* deprecations
|
||||
* Renamed confirm_in to confirm_within
|
||||
|
||||
== 0.2.3
|
||||
|
||||
* enhancements
|
||||
|
|
30
README.rdoc
30
README.rdoc
|
@ -80,16 +80,10 @@ You could also include the other devise modules as below:
|
|||
# Include authenticable + confirmable
|
||||
devise :confirmable
|
||||
|
||||
# Include authenticable + recoverable
|
||||
devise :recoverable
|
||||
# Include authenticable + recoverable + rememberable
|
||||
devise :recoverable, :rememberable
|
||||
|
||||
# Include authenticable + rememberable modules
|
||||
devise :rememberable
|
||||
|
||||
# Include authenticable + confirmable + recoverable + rememberable + validatable
|
||||
devise :confirmable, :recoverable, :rememberable, :validatable
|
||||
|
||||
# Same as above, include all of them
|
||||
# Include all of them
|
||||
devise :all
|
||||
|
||||
# Include all except recoverable
|
||||
|
@ -97,6 +91,8 @@ You could also include the other devise modules as below:
|
|||
|
||||
Note that validations aren't added by default, so you're able to customize it. In order to have automatic validations working just include :validatable.
|
||||
|
||||
== Configuration values
|
||||
|
||||
In addition to :except, you can provide some options to devise call:
|
||||
|
||||
* pepper: setup a pepper to generate de encrypted password. By default no pepper is used:
|
||||
|
@ -107,14 +103,20 @@ In addition to :except, you can provide some options to devise call:
|
|||
|
||||
devise :all, :stretches => 20
|
||||
|
||||
* confirm_in: the time the user can access the site before being blocked because his account was not confirmed
|
||||
* confirm_within: the time the user can access the site before being blocked because his account was not confirmed
|
||||
|
||||
devise :all, :confirm_in => 1.week
|
||||
devise :all, :confirm_within => 1.week
|
||||
|
||||
* remember_for: the time to store the remember me cookie in the user
|
||||
|
||||
devise :all, :remember_for => 2.weeks
|
||||
|
||||
All those values can also be set in a global way by setting them in Devise:
|
||||
|
||||
Devise.confirm_within = 1.week
|
||||
|
||||
== Routes
|
||||
|
||||
The next step after setting up your model is to configure your routes for devise. You do this by opening up your config/routes.rb and adding:
|
||||
|
||||
map.devise_for :users
|
||||
|
@ -156,7 +158,9 @@ There are also some options available for configuring your routes:
|
|||
|
||||
map.devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
|
||||
|
||||
And that is it! Devise is gonna create some helpers to use inside your controllers and views. To setup a controller that needs user authentication, just add this before_filter:
|
||||
== Controller filters
|
||||
|
||||
Devise is gonna create some helpers to use inside your controllers and views. To setup a controller that needs user authentication, just add this before_filter:
|
||||
|
||||
before_filter :authenticate_user!
|
||||
|
||||
|
@ -181,6 +185,8 @@ You also need to setup default url options for the mailer, if you are using conf
|
|||
Notifier.sender = "no-reply@yourapp.com"
|
||||
ActionMailer::Base.default_url_options = { :host => 'localhost:3000' }
|
||||
|
||||
== Tidying up
|
||||
|
||||
Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with the same authentication stuff, but not confirmation or password recovery. Just follow the same steps:
|
||||
|
||||
# Create a migration with the required fields
|
||||
|
|
|
@ -17,10 +17,10 @@ module Devise
|
|||
#
|
||||
# devise :all, :stretches => 20
|
||||
#
|
||||
# * confirm_in: the time you want your user to confirm it's account. During
|
||||
# * confirm_within: the time you want your user to confirm it's account. During
|
||||
# this time he will be able to access your application without confirming.
|
||||
#
|
||||
# devise :all, :confirm_in => 7.days
|
||||
# devise :all, :confirm_within => 7.days
|
||||
#
|
||||
# * remember_for: the time the user will be remembered without asking for
|
||||
# credentials again.
|
||||
|
|
|
@ -14,13 +14,13 @@ module Devise
|
|||
#
|
||||
# Configuration:
|
||||
#
|
||||
# confirm_in: the time you want the user will have to confirm it's account
|
||||
# without blocking his access. When confirm_in 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 7 days). By default confirm_in is
|
||||
# zero, it means users always have to confirm to sign in.
|
||||
# confirm_within: the time you want the user will have to confirm it's account
|
||||
# without blocking his access. When confirm_within 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 7 days). By default confirm_within is
|
||||
# zero, it means users always have to confirm to sign in.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
|
@ -87,21 +87,21 @@ module Devise
|
|||
#
|
||||
# Example:
|
||||
#
|
||||
# # confirm_in = 1.day and confirmation_sent_at = today
|
||||
# # confirm_within = 1.day and confirmation_sent_at = today
|
||||
# confirmation_period_valid? # returns true
|
||||
#
|
||||
# # confirm_in = 5.days and confirmation_sent_at = 4.days.ago
|
||||
# # confirm_within = 5.days and confirmation_sent_at = 4.days.ago
|
||||
# confirmation_period_valid? # returns true
|
||||
#
|
||||
# # confirm_in = 5.days and confirmation_sent_at = 5.days.ago
|
||||
# # confirm_within = 5.days and confirmation_sent_at = 5.days.ago
|
||||
# confirmation_period_valid? # returns false
|
||||
#
|
||||
# # confirm_in = 0.days
|
||||
# # confirm_within = 0.days
|
||||
# confirmation_period_valid? # will always return false
|
||||
#
|
||||
def confirmation_period_valid?
|
||||
confirmation_sent_at? &&
|
||||
(Date.today - confirmation_sent_at.to_date).days < confirm_in
|
||||
(Date.today - confirmation_sent_at.to_date).days < confirm_within
|
||||
end
|
||||
|
||||
# Checks whether the record is confirmed or not, yielding to the block
|
||||
|
@ -162,7 +162,7 @@ module Devise
|
|||
end
|
||||
end
|
||||
|
||||
Devise.model_config(self, :confirm_in, 0.days)
|
||||
Devise.model_config(self, :confirm_within, 0.days)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,7 +31,7 @@ end
|
|||
class Configurable < User
|
||||
devise :all, :stretches => 15,
|
||||
:pepper => 'abcdef',
|
||||
:confirm_in => 5.days,
|
||||
:confirm_within => 5.days,
|
||||
:remember_for => 7.days
|
||||
end
|
||||
|
||||
|
@ -97,8 +97,8 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
|||
assert_equal 'abcdef', Configurable.new.pepper
|
||||
end
|
||||
|
||||
test 'set a default value for confirm_in' do
|
||||
assert_equal 5.days, Configurable.new.confirm_in
|
||||
test 'set a default value for confirm_within' do
|
||||
assert_equal 5.days, Configurable.new.confirm_within
|
||||
end
|
||||
|
||||
test 'set a default value for remember_for' do
|
||||
|
|
|
@ -59,7 +59,7 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|||
end
|
||||
|
||||
test 'not confirmed user and setup to block without confirmation should not be able to sign in' do
|
||||
Devise.confirm_in = 0
|
||||
Devise.confirm_within = 0
|
||||
user = sign_in_as_user(:confirm => false)
|
||||
|
||||
assert_redirected_to new_user_session_path(:unconfirmed => true)
|
||||
|
@ -67,7 +67,7 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|||
end
|
||||
|
||||
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
|
||||
Devise.confirm_in = 1
|
||||
Devise.confirm_within = 1
|
||||
user = sign_in_as_user(:confirm => false)
|
||||
|
||||
assert_response :success
|
||||
|
|
|
@ -194,20 +194,20 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|||
|
||||
test 'confirm time should fallback to devise confirm in default configuration' do
|
||||
begin
|
||||
confirm_in = Devise.confirm_in
|
||||
Devise.confirm_in = 1.day
|
||||
confirm_within = Devise.confirm_within
|
||||
Devise.confirm_within = 1.day
|
||||
user = new_user
|
||||
user.confirmation_sent_at = 2.days.ago
|
||||
assert_not user.active?
|
||||
Devise.confirm_in = 3.days
|
||||
Devise.confirm_within = 3.days
|
||||
assert user.active?
|
||||
ensure
|
||||
Devise.confirm_in = confirm_in
|
||||
Devise.confirm_within = confirm_within
|
||||
end
|
||||
end
|
||||
|
||||
test 'should be active when confirmation sent at is not overpast' do
|
||||
Devise.confirm_in = 5.days
|
||||
Devise.confirm_within = 5.days
|
||||
user = create_user
|
||||
user.confirmation_sent_at = 4.days.ago
|
||||
assert user.active?
|
||||
|
@ -223,21 +223,21 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test 'should not be active when confirmation was sent within the limit' do
|
||||
Devise.confirm_in = 5.days
|
||||
Devise.confirm_within = 5.days
|
||||
user = create_user
|
||||
user.confirmation_sent_at = 5.days.ago
|
||||
assert_not user.active?
|
||||
end
|
||||
|
||||
test 'should be active when confirm in is zero' do
|
||||
Devise.confirm_in = 0.days
|
||||
Devise.confirm_within = 0.days
|
||||
user = create_user
|
||||
user.confirmation_sent_at = Date.today
|
||||
assert_not user.active?
|
||||
end
|
||||
|
||||
test 'should not be active when confirmation was sent before confirm in time' do
|
||||
Devise.confirm_in = 4.days
|
||||
Devise.confirm_within = 4.days
|
||||
user = create_user
|
||||
user.confirmation_sent_at = 5.days.ago
|
||||
assert_not user.active?
|
||||
|
|
Loading…
Add table
Reference in a new issue