简体   繁体   English

设计添加到密码更改

[英]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. 我为用户提供了一个名为“ password_changed”的属性,默认值为false,但他们希望在更改密码后将其更改为true。 Is the only way to do this to create a custom Devise password edit? 这是创建自定义Devise密码编辑的唯一方法吗? Like this ( https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-password ). 像这样( 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: 或者可以使用以下方法扩展devise注册控制器上的update方法:

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? }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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