【问题标题】::require_no_authentication filter when reset user password:require_no_authentication 过滤器重置用户密码时
【发布时间】:2019-08-30 16:31:45
【问题描述】:

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

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

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

按照此说明 - (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

config/routes.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)

谁能帮帮我?

提前谢谢你!

【问题讨论】:

  • 谢谢!我已经将此功能添加到我的应用程序中。我的问题是关于由管理员重置密码,然后由用户设置新密码。 (正如我的雇主所希望的那样)。我也解决了这个问题。我刚刚将 skip_before_action :require_no_authentication 添加到 PasswordsController.rb。

标签: ruby-on-rails ruby devise


【解决方案1】:

这种行为是正确的。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 2011-11-15
    • 2010-11-06
    • 1970-01-01
    • 2020-02-15
    • 2016-04-30
    • 1970-01-01
    相关资源
    最近更新 更多