设计身份验证 - 密码恢复后无需确认

时间:2012-05-18 18:36:43

标签: ruby-on-rails devise confirmation password-recovery

我正在使用Rails的Devise身份验证gem。

如何显示来自devise.en.yml的消息:

send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes'

发送密码恢复电子邮件后,而不是重定向到网站的根目录?

更新

我在devise_controller.rb中找到了一段有趣的代码:

def successfully_sent?(resource)
  notice = if Devise.paranoid
    resource.errors.clear
    :send_paranoid_instructions
  elsif resource.errors.empty?
    :send_instructions
  end

  if notice
    set_flash_message :notice, notice if is_navigational_format?
    true
  end
end

设置断点显示正在调用右侧行,:send_instructions 分配给通知,调用set_flash_message,但我看不到所有这些的结果,因为我我立即被重定向到根路径。

1 个答案:

答案 0 :(得分:7)

查看devise的PasswordsController的源代码:https://github.com/plataformatec/devise/blob/master/app/controllers/devise/passwords_controller.rb#L42

您必须在应用中创建一个继承自Devise :: PasswordsController的PasswordsController,仅实现after_sending_reset_password_instructions_path_for(resource_name)方法,并在设置路由时告诉devise使用您的控制器

class PasswordsController < Devise::PasswordsController
  protected
  def after_sending_reset_password_instructions_path_for(resource_name)
    #return your path
  end
end

在路线

devise_for :users, :controllers => { :passwords => "passwords" }