生产中的确认令牌无效

时间:2015-04-17 05:07:28

标签: ruby-on-rails heroku devise

我尝试了stackoverflow上已经建议的解决方案,但没有成功。在这种情况下。我正在使用Devise构建Rails应用程序进行身份验证。在开发过程中,我能够通过电子邮件链接获得确认工作。我注册了,发了一封电子邮件,然后点击了将我重定向到应用程序的链接,我确认了用户。但是,在Heroku平台的生产中,这种用户注册确认方法失败了。具体来说,我收到了消息

" 1错误禁止此用户被保存。

确认令牌无效"

在Heroku日志中,当我收到确认令牌"时,我注意到创建用户时生成的确认令牌(ee438ce80d3cc139df595771f8e058cc2eb7a91b33429d30c1ae6e4b3b00721f)与"中的确认令牌不同。确认我的帐户"由Devise发送的链接:http://bloccit.herokuapp.com/users/confirmation?confirmation_token=GvdY2xffANGxEndv8Nc_

我试图彼此,替换标记(在URL与ee438ce80d3cc139df595771f8e058cc2eb7a91b33429d30c1ae6e4b3b00721f替换GvdY2xffANGxEndv8Nc_,并且还" ee438ce80d3cc139df595771f8e058cc2eb7a91b33429d30c1ae6e4b3b00721f"与" GvdY2xffANGxEndv8Nc _"在生产数据库)仍然没有运气!

然后,我意识到人们在devise / mailer / confirmation_instructions.html.erb视图中做了一些修改。我试验并更改了文件

来自

<p>Welcome <%= @email %>!</p>

<p>You can confirm your account email through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>

<p>Welcome <%= @email %>!</p>

<p>You can confirm your account email through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>

另外,我阅读了Devise文档,说明不再建议确认注册。但是,文档仍在继续,如果要使用它,请在devise.rb文件中包含以下设置:

  

config.allow_insecure_sign_in_after_confirmation = true

我按照说明操作,对我提到的视图进行了更改。然后致力于git,并重新部署到Heroku。我发现这在User对象实例和&#34;确认我的帐户&#34;中生成了相同的确认令牌。看看Heroku日志:

  

2015-04-17T03:53:40.460157 + 00:00 app [web.1]:用户负载(1.1ms)SELECT&#34;用户&#34;。* FROM&#34;用户&#34;在哪里&#34;用户&#34;。&#34; confirmation_token&#34; = $ 1 ORDER BY&#34;用户&#34;。&#34; id&#34; ASC LIMIT 1 [[&#34; confirmation_token&#34;,&#34; aa160f928b848bb06d9c5a681dafdc00333904d9e012dd95b1b344d9c7aff20c&#34;]]
   ...   2015-04-17T03:53:40.905542 + 00:00 app [web.1]:

您可以通过以下链接确认您的帐户邮箱:


  2015-04-17T03:53:40.905533 + 00:00 app [web.1]:内容类型:text / html;
  2015-04-17T03:53:40.905544 + 00:00 app [web.1]:
  2015-04-17T03:53:40.905545 + 00:00 app [web.1]:

<a href="http://bloccit.herokuapp.com/users/confirmation?confirmation_token=aa160f928b848bb06d9c5a681dafdc00333904d9e012dd95b1b344d9c7aff20c">Confirm my account</a></p>

但是,我得到了上面提到的相同错误&#34;确认令牌无效。&#34;

我已经在这两个晚上工作了。我也不明白为什么开发中没有错误,但生产中出现错误!

病毒

1 个答案:

答案 0 :(得分:0)

您的config.action_mailer.default_url_options设置为{ host: 'bloccit.herokuapp.com' }。这是Bloc提供的示例项目。要使确认令牌有效,您只需将其设置为{ host: 'your_app_name.herokuapp.com' }