设计重置密码链接重定向到仅在生产中的主页

时间:2016-08-05 23:13:38

标签: ruby-on-rails ruby-on-rails-4 heroku devise

我遇到了设计重置密码链接(Rails 4)的问题。它已正确发送,但当用户单击该链接时,它们将被重定向到主页。

在生产中发生。它在开发中非常完美。

当它发送的链接时,它的格式正确,例如:

http://website.com/d/users/password/edit?reset_password_token=gmf7ssHx4QRmUBdGb1nr

运行rake路线,一切都告诉我它应该指向设计中的PasswordsController

new_user_password GET            /d/users/password/new(.:format)                                                             passwords#new
edit_user_password GET            /d/users/password/edit(.:format)                                                            passwords#edit
                   PATCH          /d/users/password(.:format)                                                                 passwords#update
                   PUT            /d/users/password(.:format)                                                                 passwords#update

我认为必须在PasswordsController设计中发生一些重定向。编辑方法中只有两个位置会发生重定向,require_no_authenticationassert_reset_token_passed。所以我用一些put覆盖编辑方法并检查日志。

class PasswordsController < Devise::PasswordsController


  def require_no_authentication
    assert_is_devise_resource!
    return unless is_navigational_format?
    no_input = devise_mapping.no_input_strategies

    authenticated = if no_input.present?
      args = no_input.dup.push scope: resource_name
      warden.authenticate?(*args)
    else
      warden.authenticated?(resource_name)
    end

    if authenticated && resource = warden.user(resource_name)
      flash[:alert] = I18n.t("devise.failure.already_authenticated")
      puts "=========================="
      puts "APPARENTLY IM ALREADY AUTHENTICATED WTF?"
      puts "=========================="
      redirect_to after_sign_in_path_for(resource)
    end
  end

  protected
   # Check if a reset_password_token is provided in the request
    def assert_reset_token_passed

      if params[:reset_password_token].blank?
        puts "reset_password_token is blank!!!"
        set_flash_message(:alert, :no_token)
        redirect_to new_session_path(resource_name)
      else
        puts "reset password token NOT blank"
      end

    end
end

开发结果:两个put语句都按预期显示。

生产结果:NO声明显示在任何地方。事实上,当我检查实时日志并转到重置密码链接时,它会显示它直接进入主页:

2016-08-05T23:00:15.166276+00:00 app[web.1]: Started GET "/" for 177.227.42.66 at 2016-08-05 23:00:15 +0000
2016-08-05T23:00:15.168243+00:00 app[web.1]: Processing by PageController#index as HTML

我很难过这个。日志如何不显示被调用的方法?我确认部署工作正常并重新启动了heroku服务器。

谢谢!

1 个答案:

答案 0 :(得分:1)

在请求到达正在删除路径的服务器之前,您发生了重定向。例如,example.com/aboutus在没有'/ aboutus'的情况下被重定向到www.example.com。

(将我的评论转换为答案)