ruby-on-rails - :require_no_authentication 过滤器重置用户密码时
问题描述
我在我的应用程序中重置密码时遇到问题。单击“重置密码”按钮时,我会收到一封电子邮件“重置密码说明”,其中包含指向“重置密码”的链接。
登录时 - 如果我单击电子邮件中的重置密码链接,它将被重定向到根路径,而不是密码重置页面。
注销时 - 从我的应用程序注销后,然后单击电子邮件中的重置密码链接,它会重定向到编辑密码页面。
密码控制器:
class Users::PasswordsController < Devise::PasswordsController
protected
def after_sending_reset_password_instructions_path_for(resource_name)
edit_user_registration_path
end
end
配置/路由.rb:
devise_for :users, controllers: { passwords: 'passwords' }
但仍然得到同样的错误。控制台日志:
Started GET "/users/password/edit?reset_password_token=[FILTERED]" for 127.0.0.1 at 2019-04-09 13:59:26 +0300
Processing by Users::PasswordsController#edit as HTML
Parameters: {"reset_password_token"=>"[FILTERED]"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 10], ["LIMIT", 1]]
↳ /home/anatoly/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.3ms)
谁能帮我?
先感谢您!
解决方案
这种行为是正确的。
“重置密码”页面仅用于恢复密码,因此如果用户已登录,则不会显示该页面。登录的用户可以使用该路由/users/edit
来编辑他们的密码。
以下是 Devise 的密码恢复控制器如何阻止登录用户访问“重置密码”页面:
- 控制器/设计/passwords_controller.rb#L4
- 来电
require_no_authentication
- 来电
- 设计控制器.rb#L114-L116
- 检测登录用户并重定向到
after_sign_in_path_for
路径
- 检测登录用户并重定向到
推荐阅读
- spring-integration - 使用通量通道的反应式 DSL 错误处理
- c - 哪些选项最适合在 AF UNIX 中发送/接收数据包?
- python - 在 R 与 Python 中使用 Savitzky-Golay 过滤器
- python - 从连接创建 K-mer
- java - Android RxJava 在单独的线程中处理 http 响应行
- ios - 将 CVPixelBuffer 转换为 OpenGL ES 纹理
- c# - 使用不同线程中提供的 IHubContext 与 SingalR 客户端连接
- sql - SQL 命令未正确结束联合
- python - 使用 python-firestore AsyncClient,与 firebase
- c++ - 我可以使用位字段在 C++ 中将 2 * 12 位无符号数字存储为 3 个字节吗?