简体   繁体   中英

Devise add to password change

I would like to change a simple attribute to the user after they change their password.

I have an attribute on users called "password_changed" with a default of false, but would like to change this to true after they change their password. Is the only way to do this to create a custom Devise password edit? Like this ( https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-password ). Or can I extend the update method on the devise registrations controller with something like:

def update
current_user.password_changed = true
current_user.save
end

您可以为User模型使用after_save回调:

after_save :password_changed_callback, if: Proc.new { |record| record.persisted? && record.password_changed? }

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