【发布时间】:2017-01-25 13:13:07
【问题描述】:
Rails Version: 5.0.0.1
Devise Version: 4.2
在我的 devise.rb 文件中,我将密码令牌的生命周期定义为 6 小时
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to
# change their passwords.
config.reset_password_within = 6.hours
当我选择通过忘记密码链接重置密码时,我可以看到生成的时间戳和令牌
postgres=> select reset_password_token, reset_password_sent_at from users where email='email@gmail.com';
reset_password_token | reset_password_sent_at
------------------------------------------------------------------+----------------------------
89f51bce1bc6b495c16a50b015d03897d0520a8b58c300a5deef16b2c45cac82 | 2016-09-16 21:18:01.322362
活动记录和应用程序时区都设置为'Asia/Kolkata',但是当我单击电子邮件中提供的链接并尝试更改密码(在电子邮件发送后的几分钟内)时,密码更改失败并显示消息
重置密码令牌已过期,请重新申请
更新一个
我在用户模型中启用了recoverable,但在这里没有用。
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable, :lockable, :timeoutable
end
更新二
这是实施答案中建议的更改后的日志
将设计配置更新为
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to
# change their passwords.
config.reset_password_within = 6.hours.from_now
密码更新仍然失败,日志中也没有真正的错误。
I, [2016-09-19T20:54:04.793217 #19146] INFO -- : Started PUT "/users/password" for ::1 at 2016-09-19 20:54:04 +0530
I, [2016-09-19T20:54:04.795888 #19146] INFO -- : Processing by Devise::PasswordsController#update as HTML
I, [2016-09-19T20:54:04.796108 #19146] INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"hXJycHI8Xmwo5D1pTS6a+naO1aV6PUDoqNw1kLjxWksF1zf+dEJ/j2KnmlOt0JSSe4F53cVP4uyBw1Pe0G4u8Q==", "user"=>{"reset_password_token"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Change my password"}
D, [2016-09-19T20:54:04.803200 #19146] DEBUG -- : User Load (3.8ms) SELECT "users".* FROM "users" WHERE "users"."reset_password_token" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["reset_password_token", "f278c026f607eea0f948e79e16861a90c9f1c73af271b2b803787f5fb68bdd04"], ["LIMIT", 1]]
【问题讨论】:
-
在我自己的情况下禁用
registrable不会影响我。您可能想检查您是否启用了recoverable。 -
在用户模型中启用
-
打开您的 irb 控制台并运行
Time.now以便我们查看时间是否与您的当地时间一致。 -
MacBook-Pro-2:website anadi$ irb 2.3.1 :001 > Time.now => 2016-09-17 20:30:05 +0530 2.3.1 :002 > -
我在我的回答中添加了评论。我希望这行得通。您也可以在测试它是否有效之前重新启动服务器。
标签: ruby-on-rails ruby devise