Rails 4 + Devise:密码重置始终给予“令牌无效”错误在生产服务器上,但在本地工作正常。 [英] Rails 4 + Devise: Password Reset is always giving a "Token is invalid" error on the production server, but works fine locally.

查看:152
本文介绍了Rails 4 + Devise:密码重置始终给予“令牌无效”错误在生产服务器上,但在本地工作正常。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails 4应用程序设置使用Devise,并且我正在运行密码重置的问题。我有邮件设置,密码重置电子邮件发送正常。提供的链接具有正确的reset_password_token分配给它,我用该数据库检查。但是,当我使用正确格式的密码提交表单时,会出现错误,表示重置令牌无效。

I have a Rails 4 application set up to use Devise, and I'm running a problem with password resets. I have the mailer set up, and the password reset email sends fine. The link provided has the correct reset_password_token assigned to it, which I checked with that database. However, when I submit the form with correctly formatted passwords, it gives an error saying that the reset token is invalid.

但是,完全相同的代码在本地通过 rails s 正常工作。电子邮件发送,我实际上可以重置密码。我使用的代码只是标准的Devise代码,我没有覆盖任何代码。

However, the exact same code works fine locally through rails s. The email sends, and I can actually reset the password. The code I use is just the standard Devise code, I haven't overridden any of it.

也许这是Apache的东西?我不太熟悉有人有什么想法吗?

Perhaps it's something with Apache? I'm not too familiar with it. Does anyone have any ideas?

推荐答案

检查 app / views / devise / mailer / reset_password_instructions.html.erb

Check the code in app/views/devise/mailer/reset_password_instructions.html.erb

链接应该生成:

edit_password_url(@resource,:reset_password_token => @token)

如果您的视图仍然使用此代码,成为问题的原因:

If your view still uses this code, that will be the cause of the issue:

edit_password_url(@resource,:reset_password_token => @ resource.password_reset_token)

Devise开始存储令牌的散列,所以电子邮件需要使用真实的令牌创建链接( @token )而不是存储在数据库中的哈希值。

Devise started storing hashes of the token, so the email needs to create the link using the real token (@token) rather than the hashed value stored in the database.

此更改发生在Devise中 143794d701

This change occurred in Devise in 143794d701

这篇关于Rails 4 + Devise:密码重置始终给予“令牌无效”错误在生产服务器上,但在本地工作正常。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆