【问题标题】:Devise Reset Password Link Redirecting to Homepage Only in Production仅在生产中设计重置密码链接重定向到主页
【发布时间】:2016-12-12 10:35:46
【问题描述】:

我遇到了设计重置密码链接 (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。所以我用一些 puts 覆盖了编辑方法并检查了日志。

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 语句都按预期显示。

生产结果:没有 puts 语句出现在任何地方。其实当我查看直播日志,去重设密码链接的时候,就说明是直接去首页了:

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 服务器。

谢谢!

【问题讨论】:

  • 如果未完成,请更改 production.rb 中的日志级别,config.log_level = :debug
  • 已更改:/
  • 您是否发生了 dns 重定向?例如,是否有东西在没有路径的情况下将您从 website.com/d/users/... 重定向到 www.website.com?
  • 宾果游戏。我们将 website.com 转发到 www.website.com,但显然 website.com/another-page.html 也转发到 www.website.com。请提交答案,您将收到赏金!

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-26
    • 1970-01-01
    • 2023-04-08
    • 2014-10-06
    • 2012-08-29
    相关资源
    最近更新 更多