Merge pull request #2430 from kramerc/blank-email
Avoid sending confirmations to blank emails.
This commit is contained in:
commit
486dc65884
|
@ -227,17 +227,17 @@ module Devise
|
||||||
end
|
end
|
||||||
|
|
||||||
def postpone_email_change?
|
def postpone_email_change?
|
||||||
postpone = self.class.reconfirmable && email_changed? && !@bypass_postpone
|
postpone = self.class.reconfirmable && email_changed? && !@bypass_postpone && !self.email.blank?
|
||||||
@bypass_postpone = false
|
@bypass_postpone = false
|
||||||
postpone
|
postpone
|
||||||
end
|
end
|
||||||
|
|
||||||
def reconfirmation_required?
|
def reconfirmation_required?
|
||||||
self.class.reconfirmable && @reconfirmation_required
|
self.class.reconfirmable && @reconfirmation_required && !self.email.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_confirmation_notification?
|
def send_confirmation_notification?
|
||||||
confirmation_required? && !@skip_confirmation_notification
|
confirmation_required? && !@skip_confirmation_notification && !self.email.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
|
|
@ -114,6 +114,14 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'should not send confirmation when no email is provided' do
|
||||||
|
assert_email_not_sent do
|
||||||
|
user = new_user
|
||||||
|
user.email = ''
|
||||||
|
user.save(:validate => false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test 'should find a user to send confirmation instructions' do
|
test 'should find a user to send confirmation instructions' do
|
||||||
user = create_user
|
user = create_user
|
||||||
confirmation_user = User.send_confirmation_instructions(:email => user.email)
|
confirmation_user = User.send_confirmation_instructions(:email => user.email)
|
||||||
|
@ -337,6 +345,15 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'should not send confirmation by email after changing to a blank email' do
|
||||||
|
admin = create_admin
|
||||||
|
assert admin.confirm!
|
||||||
|
assert_email_not_sent do
|
||||||
|
admin.email = ''
|
||||||
|
admin.save(:validate => false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test 'should stay confirmed when email is changed' do
|
test 'should stay confirmed when email is changed' do
|
||||||
admin = create_admin
|
admin = create_admin
|
||||||
assert admin.confirm!
|
assert admin.confirm!
|
||||||
|
|
Loading…
Reference in New Issue