Tweaks confirmation flow for signed_in users

For #2627

When allow_unconfirmed_access_for > 0, users may
be already signed in at the time they confirm
their account. Consequently, the default
confirmation should be compatible with this
possibility. Additionally, they should not be
redirected to the sign in form after confirmation
in this case. So I've changed
ConfirmationsController#after_confirmation_path_for
to send the user to the root path when signed in,
or the sign in form otherwise.

Conflicts:
	app/controllers/devise/confirmations_controller.rb
	config/locales/en.yml
This commit is contained in:
Greg Gates
2013-09-16 10:12:15 -04:00
committed by José Valim
parent 08edcc10fe
commit e3d0a2ba45
3 changed files with 14 additions and 2 deletions

View File

@@ -43,6 +43,8 @@ class Devise::ConfirmationsController < DeviseController
def after_confirmation_path_for(resource_name, resource)
if Devise.allow_insecure_sign_in_after_confirmation
after_sign_in_path_for(resource)
elsif signed_in?
signed_in_root_path(resource)
else
new_session_path(resource_name)
end

View File

@@ -3,7 +3,7 @@
en:
devise:
confirmations:
confirmed: "Your account was successfully confirmed. Please sign in."
confirmed: "Your account was successfully confirmed."
confirmed_and_signed_in: "Your account was successfully confirmed. You are now signed in."
send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."

View File

@@ -56,7 +56,7 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
assert_not user.confirmed?
visit_user_confirmation_with_token(user.raw_confirmation_token)
assert_contain 'Your account was successfully confirmed. Please sign in.'
assert_contain 'Your account was successfully confirmed.'
assert_current_url '/users/sign_in'
assert user.reload.confirmed?
end
@@ -135,6 +135,16 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
end
end
test 'unconfirmed but signed in user should be redirected to their root path' do
swap Devise, :allow_unconfirmed_access_for => 1.day do
user = sign_in_as_user(:confirm => false)
visit_user_confirmation_with_token(user.raw_confirmation_token)
assert_contain 'Your account was successfully confirmed.'
assert_current_url '/'
end
end
test 'error message is configurable by resource name' do
store_translations :en, :devise => {
:failure => { :user => { :unconfirmed => "Not confirmed user" } }