首页 > 解决方案 > :require_no_authentication 过滤器重置用户密码时

问题描述

我在我的应用程序中重置密码时遇到问题。单击“重置密码”按钮时,我会收到一封电子邮件“重置密码说明”,其中包含指向“重置密码”的链接。

登录时 - 如果我单击电子邮件中的重置密码链接,它将被重定向到根路径,而不是密码重置页面。

注销时 - 从我的应用程序注销后,然后单击电子邮件中的重置密码链接,它会重定向到编辑密码页面。

按照此说明 - (https://github.com/plataformatec/devise/wiki/How-To:-Redirect-URL-after-sending-reset-password-instructions

密码控制器:

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)

谁能帮我?

先感谢您!

标签: ruby-on-railsrubydevise

解决方案


这种行为是正确的。

“重置密码”页面仅用于恢复密码,因此如果用户已登录,则不会显示该页面。登录的用户可以使用该路由/users/edit来编辑他们的密码。

以下是 Devise 的密码恢复控制器如何阻止登录用户访问“重置密码”页面:


推荐阅读