gpt4 book ai didi

ruby-on-rails - 更改密码时防止设计发送电子邮件

转载 作者:行者123 更新时间:2023-12-04 00:09:02 25 4
gpt4 key购买 nike

我在我的 Rails 3 应用程序中使用 Devise。当前重置密码的行为是点击“忘记密码?”关联。这里的链接是:

(url)/password/new.user

这将调用设计passwords_controller.rb中的以下方法:

def new
build_resource({})
end

这个方法可以:

  1. 生成密码重置 token 并将其添加到数据库中,

  2. 通过包含 token 的链接向此人发送电子邮件:

    (url)/password/edit?reset_password_token=xxxxxxxxxxxxxxx

有什么方法可以说服 Devise 只执行第 1 步而不执行第 2 步?如果可能的话,是否有任何我应该注意的安全问题,并且我确实采用了这种方法来简化网站的一部分。

最佳答案

我建议在您的用户 (?) 模型上覆盖 send_devise_notification,并在通知值为 :reset_password_instructions 时返回 true。像这样的:

# app/models/user.rb
def send_devise_notification(notification)
return true if notification == :reset_password_instructions
end

查看他们的示例,了解如何覆盖/自定义发送电子邮件的行为 https://github.com/plataformatec/devise/blob/master/lib/devise/models/authenticatable.rb#L127

关于ruby-on-rails - 更改密码时防止设计发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14634356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com