mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Checking if unconfirmed_email has changed before to set update_needs_confirmation flash message.
Conflicts: test/integration/registerable_test.rb Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
This commit is contained in:
parent
1da8490dbc
commit
73f617db7b
2 changed files with 32 additions and 5 deletions
|
@ -38,13 +38,13 @@ class Devise::RegistrationsController < DeviseController
|
|||
# the current user in place.
|
||||
def update
|
||||
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
|
||||
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
|
||||
|
||||
if resource.update_with_password(resource_params)
|
||||
if is_navigational_format?
|
||||
if resource.respond_to?(:pending_reconfirmation?) && resource.pending_reconfirmation?
|
||||
flash_key = :update_needs_confirmation
|
||||
end
|
||||
set_flash_message :notice, flash_key || :updated
|
||||
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
|
||||
:update_needs_confirmation : :updated
|
||||
set_flash_message :notice, flash_key
|
||||
end
|
||||
sign_in resource_name, resource, :bypass => true
|
||||
respond_with resource, :location => after_update_path_for(resource)
|
||||
|
@ -74,6 +74,12 @@ class Devise::RegistrationsController < DeviseController
|
|||
|
||||
protected
|
||||
|
||||
def update_needs_confirmation?(resource, previous)
|
||||
resource.respond_to?(:pending_reconfirmation?) &&
|
||||
resource.pending_reconfirmation? &&
|
||||
previous != resource.unconfirmed_email
|
||||
end
|
||||
|
||||
# Build a devise resource passing in the session. Useful to move
|
||||
# temporary session data to the newly created user.
|
||||
def build_resource(hash=nil)
|
||||
|
|
|
@ -321,4 +321,25 @@ class ReconfirmableRegistrationTest < ActionController::IntegrationTest
|
|||
|
||||
assert Admin.first.valid_password?('pas123')
|
||||
end
|
||||
end
|
||||
|
||||
test 'a signed in admin should not see a reconfirmation message if he did not change his email, despite having an unconfirmed email' do
|
||||
sign_in_as_admin
|
||||
|
||||
get edit_admin_registration_path
|
||||
fill_in 'email', :with => 'admin.new@example.com'
|
||||
fill_in 'current password', :with => '123456'
|
||||
click_button 'Update'
|
||||
|
||||
get edit_admin_registration_path
|
||||
fill_in 'password', :with => 'pas123'
|
||||
fill_in 'password confirmation', :with => 'pas123'
|
||||
fill_in 'current password', :with => '123456'
|
||||
click_button 'Update'
|
||||
|
||||
assert_current_url '/admin_area/home'
|
||||
assert_contain 'You updated your account successfully.'
|
||||
|
||||
assert_equal "admin.new@example.com", Admin.first.unconfirmed_email
|
||||
assert Admin.first.valid_password?('pas123')
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue