只允许在电子邮件确认后重置设备密码

问题描述 投票:3回答:1

我有一个非常标准的设备安装,同时配备了 recoverableconfirmable 启用。

问题是,如果用户还没有确认他们的电子邮件,我需要禁用密码重置。

例如

  • 用户用电子邮件注册 [email protected]
  • 确认信发出
  • 用户在确认自己的邮箱之前,先去重置密码。
  • 重置密码邮件 不该发
ruby-on-rails email devise
1个回答
0
投票

我知道这是一个老问题,但我有同样的用例,并通过覆盖devise的用户模型的send_reset_password_instructions方法解决了这个问题。这是我的方法的最终版本。

def self.send_reset_password_instructions(attributes={})
  recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)

  if (recoverable.persisted? && !recoverable.confirmed?)
    recoverable.errors.add(:email, I18n.t('devise.failure.not_verified'))
  else
    recoverable.send_reset_password_instructions
  end

  recoverable
end

更具体地说,如果一个用户被持久化在数据库中 但没有通过电子邮件验证,就添加一个错误& 省略重置密码电子邮件发送。

© www.soinside.com 2019 - 2024. All rights reserved.