简体   繁体   中英

send password change confirmation with devise

I want to configure devise to send a confirmation email when the user has changed their password as a security measure. I'd prefer to re-use my devise mailers if possible. Any ideas how to do this?

Untested, but I'd try to do this within your User model with a simple after_update callback:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :recoverable # whatever

  after_update :send_password_changed_notification

  # attr_accessible, validations, ...


  private

    def send_password_changed_notification
      # Send email with the mailer of your choice,
      # e. g. your existing custom Devise mailer:
      YourDeviseMailer.password_changed_notification(self).deliver if password_changed?
    end
end

I would configure the update user action, you can read on how to do that in their documentation . Check how devise handles confirmations of new registered users in registration action and re-use that code in your new reset password action.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM