When using reconfirmable, notify the original email about the change right away
Do not wait for the email change to be confirmed by the "unconfirmed email" with reconfirmable: notify the original email right away.
This commit is contained in:
parent
70eb18d766
commit
8387cc9474
|
@ -277,6 +277,16 @@ module Devise
|
||||||
confirmation_required? && !@skip_confirmation_notification && self.email.present?
|
confirmation_required? && !@skip_confirmation_notification && self.email.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# With reconfirmable, notify the original email when the user first
|
||||||
|
# requests the email change, instead of when the change is confirmed.
|
||||||
|
def send_email_change_notification?
|
||||||
|
if self.class.reconfirmable
|
||||||
|
self.class.send_email_change_notification && reconfirmation_required?
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# A callback initiated after successfully confirming. This can be
|
# A callback initiated after successfully confirming. This can be
|
||||||
# used to insert your own logic that is only run after the user successfully
|
# used to insert your own logic that is only run after the user successfully
|
||||||
# confirms.
|
# confirms.
|
||||||
|
|
|
@ -516,4 +516,21 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
||||||
admin.save
|
admin.save
|
||||||
assert admin.pending_reconfirmation?
|
assert admin.pending_reconfirmation?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'should notify previous email on email change when configured' do
|
||||||
|
swap Devise, send_email_change_notification: true do
|
||||||
|
admin = create_admin
|
||||||
|
original_email = admin.email
|
||||||
|
|
||||||
|
assert_difference 'ActionMailer::Base.deliveries.size', 2 do
|
||||||
|
assert admin.update_attributes(email: 'new-email@example.com')
|
||||||
|
end
|
||||||
|
assert_equal original_email, ActionMailer::Base.deliveries[-2]['to'].to_s
|
||||||
|
assert_equal 'new-email@example.com', ActionMailer::Base.deliveries[-1]['to'].to_s
|
||||||
|
|
||||||
|
assert_email_not_sent do
|
||||||
|
assert admin.confirm
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue