Browse Source

send email changed notification to old email

pull/1820/head
Jack S 3 years ago
parent
commit
ee33c787d1
  1. 27
      app/mailers/devise_notify_mailer.rb
  2. 2
      config/initializers/devise.rb

27
app/mailers/devise_notify_mailer.rb

@ -36,8 +36,9 @@ class DeviseNotifyMailer < Devise::Mailer
def confirmation_instructions(record, token, _opts = {})
username = record.email
if email_changed(record)
if email_changed?(record)
username = record.unconfirmed_email
send_email_changed_to_old_email(record)
send_confirmation_email(record.unconfirmed_email, record, token, username)
end
send_confirmation_email(record.email, record, token, username)
@ -54,9 +55,11 @@ class DeviseNotifyMailer < Devise::Mailer
Rails.application.credentials[:email_allowlist] || []
end
def email_changed(record, _opts = {})
# TODO: do not send if user changed own email address
return true if intercept_send?(email)
def send_email_changed_to_old_email(record)
# Do not send if user changed own email
return if record.versions.last.actor == record
return true if intercept_send?(record.email)
send_email(
record.email,
@ -68,6 +71,22 @@ class DeviseNotifyMailer < Devise::Mailer
)
end
def email_changed?(record)
# binding.pry
# record.versions.last.changeset.has_key? "unconfirmed_email"
record.confirmable_template == User::CONFIRMABLE_TEMPLATE_ID && (record.unconfirmed_email.present? && record.unconfirmed_email != record.email)
end
def send_confirmation_email(email, record, token, username)
url = "#{user_confirmation_url}?confirmation_token="
send_email(
email,
record.confirmable_template,
personalisation(record, token, url, username:),
)
end
# def unlock_instructions(record, token, opts = {})
# super
# end

2
config/initializers/devise.rb

@ -130,7 +130,7 @@ Devise.setup do |config|
# config.pepper = '1c69067fda44e12f0ea1e8573fcdb122e5ff7e51a28cc6944c2548af7b7cbfe1400739e2d71cdf0ab53a3b60305942301d7fd7f43ff3a51316e51438145d80ad'
# Send a notification to the original email when the user's email is changed.
config.send_email_changed_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

Loading…
Cancel
Save