Devise authentication - no confirmation after password recovery

烈酒焚心 提交于 2019-12-07 16:47:24

问题


I'm using Devise authentication gem with Rails.

How to display the message from devise.en.yml:

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

after password recovery e-mail has been sent, instead of being redirected to site's root?

Update:

I've found an interesting piece of code in 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

Setting breakpoints shows that the right lines are being called, :send_instructions is assigned to notice , set_flash_message is called, but I cannot see the result of all this because I am immediately redirected to root path.


回答1:


Look at the source code for devise's PasswordsController: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/passwords_controller.rb#L42

You'll have to create a PasswordsController in your app that inherits from Devise::PasswordsController, implement only the after_sending_reset_password_instructions_path_for(resource_name) method and when setting the routes tell devise to use your controller

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

in routes

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


来源:https://stackoverflow.com/questions/10658004/devise-authentication-no-confirmation-after-password-recovery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!