Change email_change => email_changed notification

This better indicates what the setting is for, and when it's supposed to
be triggered.

We might eventually deprecate the existing password_change on in favor
of password_changed.
This commit is contained in:
Carlos Antonio da Silva 2017-03-10 08:56:33 -03:00
parent d7f6855ad8
commit 2135ae5e5e
11 changed files with 19 additions and 19 deletions

View File

@ -4,7 +4,7 @@
* `Devise::Mailer#scope_name` and `Devise::Mailer#resource` are now protected
methods instead of public.
* enhancements
* Notify the original email when it is changed with a new `Devise.send_email_change_notification` setting.
* Notify the original email when it is changed with a new `Devise.send_email_changed_notification` setting.
When using `reconfirmable`, the notification will be sent right away instead of when the unconfirmed email is confirmed.
(original change by @ethirajsrinivasan)

View File

@ -17,8 +17,8 @@ if defined?(ActionMailer)
devise_mail(record, :unlock_instructions, opts)
end
def email_change(record, opts={})
devise_mail(record, :email_change, opts)
def email_changed(record, opts={})
devise_mail(record, :email_changed, opts)
end
def password_change(record, opts={})

View File

@ -23,7 +23,7 @@ en:
subject: "Reset password instructions"
unlock_instructions:
subject: "Unlock instructions"
email_change:
email_changed:
subject: "Email Changed"
password_change:
subject: "Password Changed"

View File

@ -154,8 +154,8 @@ module Devise
@@pepper = nil
# Used to send notification to the original user email when their email is changed.
mattr_accessor :send_email_change_notification
@@send_email_change_notification = false
mattr_accessor :send_email_changed_notification
@@send_email_changed_notification = false
# Used to enable sending notification to user when their password is changed.
mattr_accessor :send_password_change_notification

View File

@ -26,7 +26,7 @@ module Devise
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field to be set up (t.reconfirmable in migrations). Until confirmed, new email is
# stored in unconfirmed email column, and copied to email column on successful
# confirmation. Also, when used in conjunction with `send_email_change_notification`,
# confirmation. Also, when used in conjunction with `send_email_changed_notification`,
# the notification is sent to the original email when the change is requested,
# not when the unconfirmed email is confirmed.
# * +confirm_within+: the time before a sent confirmation token becomes invalid.
@ -281,9 +281,9 @@ module Devise
# 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?
def send_email_changed_notification?
if self.class.reconfirmable
self.class.send_email_change_notification && reconfirmation_required?
self.class.send_email_changed_notification && reconfirmation_required?
else
super
end

View File

@ -14,7 +14,7 @@ module Devise
#
# * +stretches+: the cost given to bcrypt.
#
# * +send_email_change_notification+: notify original email when it changes.
# * +send_email_changed_notification+: notify original email when it changes.
#
# * +send_password_change_notification+: notify email when password changes.
#
@ -26,7 +26,7 @@ module Devise
extend ActiveSupport::Concern
included do
after_update :send_email_change_notification, if: :send_email_change_notification?
after_update :send_email_changed_notification, if: :send_email_changed_notification?
after_update :send_password_change_notification, if: :send_password_change_notification?
attr_reader :password, :current_password
@ -138,8 +138,8 @@ module Devise
end
# Send notification to user when email changes.
def send_email_change_notification
send_devise_notification(:email_change, to: email_was)
def send_email_changed_notification
send_devise_notification(:email_changed, to: email_was)
end
# Send notification to user when password changes.
@ -158,8 +158,8 @@ module Devise
Devise::Encryptor.digest(self.class, password)
end
def send_email_change_notification?
self.class.send_email_change_notification && email_changed?
def send_email_changed_notification?
self.class.send_email_changed_notification && email_changed?
end
def send_password_change_notification?
@ -167,7 +167,7 @@ module Devise
end
module ClassMethods
Devise::Models.config(self, :pepper, :stretches, :send_email_change_notification, :send_password_change_notification)
Devise::Models.config(self, :pepper, :stretches, :send_email_changed_notification, :send_password_change_notification)
# We assume this method already gets the sanitized values from the
# DatabaseAuthenticatable strategy. If you are using this method on

View File

@ -111,7 +111,7 @@ Devise.setup do |config|
# config.pepper = '<%= SecureRandom.hex(64) %>'
# Send a notification to the original email when the user's email is changed.
# config.send_email_change_notification = false
# config.send_email_changed_notification = false
# Send a notification email when the user's password is changed.
# config.send_password_change_notification = false

View File

@ -518,7 +518,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
end
test 'should notify previous email on email change when configured' do
swap Devise, send_email_change_notification: true do
swap Devise, send_email_changed_notification: true do
admin = create_admin
original_email = admin.email

View File

@ -237,7 +237,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
end
test 'should notify previous email on email change when configured' do
swap Devise, send_email_change_notification: true do
swap Devise, send_email_changed_notification: true do
user = create_user
original_email = user.email
assert_email_sent original_email do