【问题标题】:How to verify account termination with user's password in Rails app?如何在 Rails 应用程序中使用用户密码验证帐户终止?
【发布时间】:2013-10-29 04:35:12
【问题描述】:

我按照this tutorial(以及其他)从头开始为我的 Rails 应用程序构建了身份验证系统。

一切都按预期工作,但用户仍然很容易破坏自己的帐户(以及其中包含的所有数据):

class UsersController < ApplicationController

  def destroy
    @user.destroy
    flash[:success] = "Your account has been deleted."
    redirect_to root_path
  end

end

现在,我的 edit 视图中有这个:

<%= link_to "Delete own account", @user, :confirm => "Are you REALLY sure?", :method => :delete %>

Rails 方法是什么来扩展此功能并要求用户提供密码才能销毁自己的帐户?

感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3


    【解决方案1】:

    您必须为此添加一些逻辑。

    按照这个:

    1. 创建表单 *使用form_for) 在destroy/(您想要的任何页面)上询问登录用户的密码。 路由表单以执行某些操作。
    2. 在发送的action中,根据提供的密码验证用户;如果匹配,则调用@user.destroy,否则,flash 错误和警告等。

    【讨论】:

    • 好的,感谢您为我指明了正确的方向。不过,我又被卡住了,并发布了another question
    猜你喜欢
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    相关资源
    最近更新 更多