Send confirmation instructions when a user updates the email address from nil

This commit is contained in:
MatBi
2016-04-18 18:15:32 +08:00
committed by Ulisses Almeida
parent 812c1de8e8
commit 1d57169c7b
2 changed files with 16 additions and 7 deletions

View File

@@ -170,6 +170,7 @@ module Devise
# in models to map to a nice sign up e-mail.
def send_on_create_confirmation_instructions
send_confirmation_instructions
skip_reconfirmation!
end
# Callback to overwrite if confirmation is required or not.
@@ -254,13 +255,13 @@ module Devise
end
def postpone_email_change?
postpone = self.class.reconfirmable && email_changed? && email_was.present? && !@bypass_confirmation_postpone && self.email.present?
postpone = self.class.reconfirmable && email_changed? && !@bypass_confirmation_postpone && self.email.present?
@bypass_confirmation_postpone = false
postpone
end
def reconfirmation_required?
self.class.reconfirmable && @reconfirmation_required && self.email.present?
self.class.reconfirmable && @reconfirmation_required && (self.email.present? || self.unconfirmed_email.present?)
end
def send_confirmation_notification?

View File

@@ -114,7 +114,7 @@ class ConfirmableTest < ActiveSupport::TestCase
assert_email_not_sent do
user.save!
assert !user.confirmed?
assert_not user.confirmed?
end
end
@@ -401,6 +401,14 @@ class ReconfirmableTest < ActiveSupport::TestCase
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
end
test 'should send confirmation instructions by email after changing email from nil' do
admin = create_admin(email: nil)
assert_email_sent "new_test@example.com" do
assert admin.update_attributes(email: 'new_test@example.com')
end
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
end
test 'should not send confirmation by email after changing password' do
admin = create_admin
assert admin.confirm
@@ -488,8 +496,8 @@ class ReconfirmableTest < ActiveSupport::TestCase
end
test 'should not require reconfirmation after creating a record' do
user = create_admin
assert !user.pending_reconfirmation?
admin = create_admin
assert !admin.pending_reconfirmation?
end
test 'should not require reconfirmation after creating a record with #save called in callback' do
@@ -497,7 +505,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
after_create :save
end
user = Admin::WithSaveInCallback.create(valid_attributes.except(:username))
assert !user.pending_reconfirmation?
admin = Admin::WithSaveInCallback.create(valid_attributes.except(:username))
assert !admin.pending_reconfirmation?
end
end