【问题标题】:Devise confirmation link not working设计确认链接不起作用
【发布时间】:2014-11-03 17:54:31
【问题描述】:

这里真的很烦。在我的 Rails 应用程序中,所有电子邮件都通过 Mandrill 通过 SMTP 发送;该应用程序本身托管在 Heroku 上。 Devise gem 似乎一切正常——用户可以注册、登录等。但是,电子邮件中包含的确认链接不起作用。

看起来像这样:

http://anymarket.co/users/confirmation?confirmation_token=1fde79fe312eec0efc733e77f946aba5d7b227cbdfeb54e429f9a0e6f369a5cd

当我单击链接并检查日志时,似乎唯一发生的事情是将用户定向到站点的根目录。 ConfirmationsController#show 操作永远不会加载。

我真的不确定问题出在哪里。在我的 routes.rb 文件的开头我有这个:

devise_for :users, :controllers => { :registrations => 'registrations' }
default_url_options :host => "anymarket.co"

我用这个覆盖 RegistrationsController:

class RegistrationsController < Devise::RegistrationsController
  before_filter :authenticate_user!, :except => [:after_inactive_sign_up_path_for]

    def new 
        respond_to do |format|
            format.js
            format.html
        end
    end

    def create
    build_resource(sign_up_params)

    resource_saved = resource.save
    yield resource if block_given?
    if resource_saved
      if resource.active_for_authentication?
                set_flash_message :onboard, :signed_up if is_flashing_format?
        sign_up(resource_name, resource)
        respond_with resource, location: after_sign_up_path_for(resource)
      else
                set_flash_message :onboard, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      @validatable = devise_mapping.validatable?
      if @validatable
        @minimum_password_length = resource_class.password_length.min
      end
      respond_with resource
    end
  end

  def after_inactive_sign_up_path_for(user)
        respond_to do |format|
             format.html {render :action => "/"}
    end
  end

    private

  def sign_up_params
    params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :avatar, :school, :provider, :uid)
  end

  def account_update_params 
    params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password, :avatar, :braintree_customer_id)
  end

end

有什么想法我在这里做错了吗??

编辑:rake 路由的结果 | grep 确认

user_confirmation POST   /users/confirmation(.:format)              devise/confirmations#create                                                                  
    new_user_confirmation GET    /users/confirmation/new(.:format)          devise/confirmations#new                                                                     
                          GET    /users/confirmation(.:format)              devise/confirmations#show    

跟踪日志,当新用户点击确认链接时会发生这种情况

Started GET "/" for 98.245.3.223 at 2014-09-10 07:29:36 +0000                                                               
2014-09-10T07:29:36.706263+00:00 app[web.1]:   Rendered home/index.html.erb within layouts/application (104.6ms)                                                         
2014-09-10T07:29:36.709496+00:00 app[web.1]: Completed 200 OK in 112ms (Views: 96.9ms | ActiveRecord: 12.6ms)                                                            
2014-09-10T07:29:36.597154+00:00 app[web.1]: Processing by HomeController#index as HTML                                                                                  
2014-09-10T07:29:36.708971+00:00 app[web.1]:   Rendered layouts/_no_cc_alert.html.erb (0.2ms)                                                                            
2014-09-10T07:29:36.718357+00:00 heroku[router]: at=info method=GET path="/" host=www.anymarket.co request_id=a42fa3d1-f7a2-4871-92d7-14278f93cae7 fwd="98.245.3.223" dyn
o=web.1 connect=2ms service=126ms status=200 bytes=1036  

【问题讨论】:

  • 请执行rake routes | grep confirmation并在您的帖子中显示结果。
  • @ForgetTheNorm - 好的,更新了
  • 很奇怪。您说进入http://anymarket.co/users/confirmation?... 的GET 路由到您的根目录,但您的配置似乎路由到devise/confirmations#show。当用户点击此链接时,完整的日志是什么?
  • 为此更新了尾部。没有发生太多事情,但是“/”根的渲染。它可能与我在 RegistrationsController 中的 after_inactive_sign_up_path_for(user) 操作有关吗?
  • 更新:不。我不知道问题是什么。

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


【解决方案1】:

你的 ssl 配置错误

如果您想发送链接: http://anymarket.co/users/confirmation?confirmation_token=1fde79fe312eec0efc733e77f946aba5d7b227cbdfeb54e429f9a0e6f369a5cd

有两个问题,首先你得到了纯 http 端口 80 未加密的协议,但是你配置了 ssl,所以你被重定向到 https 协议。第二个是您将 www.anymarket.co 配置为 ssl 端点而不是 anymarket.co,因为您正在获取子域上的索引页面。 你可以用 curl 测试一下:

curl -kvI https://anymarket.co

curl -kvI https://www.anymarket.co

换句话说,你在邮件中的链接应该是这样的

https://www.anymarket.co/users/confirmation?confirmation_token=1fde79fe312eec0efc733e77f946aba5d7b227cbdfeb54e429f9a0e6f369a5cd

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多