我有一个非常标准的设备安装,同时配备了 recoverable
和 confirmable
启用。
问题是,如果用户还没有确认他们的电子邮件,我需要禁用密码重置。
例如
我知道这是一个老问题,但我有同样的用例,并通过覆盖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
更具体地说,如果一个用户被持久化在数据库中 但没有通过电子邮件验证,就添加一个错误& 省略重置密码电子邮件发送。