mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
Rename active? to active_for_authentication?
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
# Deny user access whenever his account is not active yet. All strategies that inherits from
|
||||
# Devise::Strategies::Authenticatable and uses the validate already check if the user is active?
|
||||
# Devise::Strategies::Authenticatable and uses the validate already check if the user is active_for_authentication?
|
||||
# before actively signing him in. However, we need this as hook to validate the user activity
|
||||
# in each request and in case the user is using other strategies beside Devise ones.
|
||||
Warden::Manager.after_set_user do |record, warden, options|
|
||||
if record && record.respond_to?(:active?) && !record.active?
|
||||
if record && record.respond_to?(:active_for_authentication?) && !record.active_for_authentication?
|
||||
scope = options[:scope]
|
||||
warden.logout(scope)
|
||||
throw :warden, :scope => scope, :message => record.inactive_message
|
||||
|
||||
@@ -24,19 +24,19 @@ module Devise
|
||||
# * +params_authenticatable+: if this model allows authentication through request params. By default true.
|
||||
# It also accepts an array specifying the strategies that should allow params authentication.
|
||||
#
|
||||
# == Active?
|
||||
# == active_for_authentication?
|
||||
#
|
||||
# Before authenticating a user and in each request, Devise checks if your model is active by
|
||||
# calling model.active?. This method is overwriten by other devise modules. For instance,
|
||||
# :confirmable overwrites .active? to only return true if your model was confirmed.
|
||||
# calling model.active_for_authentication?. This method is overwriten by other devise modules. For instance,
|
||||
# :confirmable overwrites .active_for_authentication? to only return true if your model was confirmed.
|
||||
#
|
||||
# You overwrite this method yourself, but if you do, don't forget to call super:
|
||||
#
|
||||
# def active?
|
||||
# def active_for_authentication?
|
||||
# super && special_condition_is_valid?
|
||||
# end
|
||||
#
|
||||
# Whenever active? returns false, Devise asks the reason why your model is inactive using
|
||||
# Whenever active_for_authentication? returns false, Devise asks the reason why your model is inactive using
|
||||
# the inactive_message method. You can overwrite it as well:
|
||||
#
|
||||
# def inactive_message
|
||||
@@ -55,10 +55,10 @@ module Devise
|
||||
# find_for_authentication are the methods used in a Warden::Strategy to check
|
||||
# if a model should be signed in or not.
|
||||
#
|
||||
# However, you should not overwrite this method, you should overwrite active? and
|
||||
# inactive_message instead.
|
||||
# However, you should not overwrite this method, you should overwrite active_for_authentication?
|
||||
# and inactive_message instead.
|
||||
def valid_for_authentication?
|
||||
if active?
|
||||
if active_for_authentication?
|
||||
block_given? ? yield : true
|
||||
else
|
||||
inactive_message
|
||||
@@ -66,7 +66,19 @@ module Devise
|
||||
end
|
||||
|
||||
def active?
|
||||
true
|
||||
ActiveSupport::Deprecation.warn "[DEVISE] active? is deprecated, please use active_for_authentication? instead.", caller
|
||||
active_for_authentication?
|
||||
end
|
||||
|
||||
def active_for_authentication?
|
||||
my_methods = self.class.instance_methods(false)
|
||||
if my_methods.include?("active?") || my_methods.include?(:active?)
|
||||
ActiveSupport::Deprecation.warn "[DEVISE] Overriding active? is deprecated to avoid conflicts. " \
|
||||
"Please use active_for_authentication? instead.", caller
|
||||
active?
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def inactive_message
|
||||
|
||||
@@ -55,11 +55,11 @@ module Devise
|
||||
unless_confirmed { send_confirmation_instructions }
|
||||
end
|
||||
|
||||
# Overwrites active? from Devise::Models::Activatable for confirmation
|
||||
# Overwrites active_for_authentication? for confirmation
|
||||
# by verifying whether a user is active to sign in or not. If the user
|
||||
# is already confirmed, it should never be blocked. Otherwise we need to
|
||||
# calculate if the confirm time has not expired for this user.
|
||||
def active?
|
||||
def active_for_authentication?
|
||||
super && (!confirmation_required? || confirmed? || confirmation_period_valid?)
|
||||
end
|
||||
|
||||
|
||||
@@ -57,9 +57,9 @@ module Devise
|
||||
if_access_locked { send_unlock_instructions }
|
||||
end
|
||||
|
||||
# Overwrites active? from Devise::Models::Activatable for locking purposes
|
||||
# Overwrites active_for_authentication? from Devise::Models::Activatable for locking purposes
|
||||
# by verifying whether a user is active to sign in or not based on locked?
|
||||
def active?
|
||||
def active_for_authentication?
|
||||
super && !access_locked?
|
||||
end
|
||||
|
||||
|
||||
@@ -167,10 +167,10 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
swap Devise, :confirm_within => 1.day do
|
||||
user = new_user
|
||||
user.confirmation_sent_at = 2.days.ago
|
||||
assert_not user.active?
|
||||
assert_not user.active_for_authentication?
|
||||
|
||||
Devise.confirm_within = 3.days
|
||||
assert user.active?
|
||||
assert user.active_for_authentication?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -180,35 +180,35 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
user = create_user
|
||||
|
||||
user.confirmation_sent_at = 4.days.ago
|
||||
assert user.active?
|
||||
assert user.active_for_authentication?
|
||||
|
||||
user.confirmation_sent_at = 5.days.ago
|
||||
assert_not user.active?
|
||||
assert_not user.active_for_authentication?
|
||||
end
|
||||
end
|
||||
|
||||
test 'should be active when already confirmed' do
|
||||
user = create_user
|
||||
assert_not user.confirmed?
|
||||
assert_not user.active?
|
||||
assert_not user.active_for_authentication?
|
||||
|
||||
user.confirm!
|
||||
assert user.confirmed?
|
||||
assert user.active?
|
||||
assert user.active_for_authentication?
|
||||
end
|
||||
|
||||
test 'should not be active when confirm in is zero' do
|
||||
Devise.confirm_within = 0.days
|
||||
user = create_user
|
||||
user.confirmation_sent_at = Date.today
|
||||
assert_not user.active?
|
||||
assert_not user.active_for_authentication?
|
||||
end
|
||||
|
||||
test 'should not be active without confirmation' do
|
||||
user = create_user
|
||||
user.confirmation_sent_at = nil
|
||||
user.save
|
||||
assert_not user.reload.active?
|
||||
assert_not user.reload.active_for_authentication?
|
||||
end
|
||||
|
||||
test 'should be active without confirmation when confirmation is not required' do
|
||||
@@ -216,7 +216,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
user.instance_eval { def confirmation_required?; false end }
|
||||
user.confirmation_sent_at = nil
|
||||
user.save
|
||||
assert user.reload.active?
|
||||
assert user.reload.active_for_authentication?
|
||||
end
|
||||
|
||||
test 'should find a user to send email instructions for the user confirm it\'s email by authentication_keys' do
|
||||
|
||||
@@ -47,12 +47,12 @@ class LockableTest < ActiveSupport::TestCase
|
||||
assert user.access_locked?
|
||||
end
|
||||
|
||||
test "active? should be the opposite of locked?" do
|
||||
test "active_for_authentication? should be the opposite of locked?" do
|
||||
user = create_user
|
||||
user.confirm!
|
||||
assert user.active?
|
||||
assert user.active_for_authentication?
|
||||
user.lock_access!
|
||||
assert_not user.active?
|
||||
assert_not user.active_for_authentication?
|
||||
end
|
||||
|
||||
test "should unlock a user by cleaning locked_at, falied_attempts and unlock_token" do
|
||||
|
||||
@@ -19,7 +19,7 @@ class TestHelpersTest < ActionController::TestCase
|
||||
test "redirects if attempting to access a page with an unconfirmed account" do
|
||||
swap Devise, :confirm_within => 0 do
|
||||
user = create_user
|
||||
assert !user.active?
|
||||
assert !user.active_for_authentication?
|
||||
|
||||
sign_in user
|
||||
get :index
|
||||
@@ -30,7 +30,7 @@ class TestHelpersTest < ActionController::TestCase
|
||||
test "returns nil if accessing current_user with an unconfirmed account" do
|
||||
swap Devise, :confirm_within => 0 do
|
||||
user = create_user
|
||||
assert !user.active?
|
||||
assert !user.active_for_authentication?
|
||||
|
||||
sign_in user
|
||||
get :accept, :id => user
|
||||
|
||||
Reference in New Issue
Block a user