ruby-on-rails - 如何通过设计和更新绕过辞职

标签 ruby-on-rails authentication devise passwords

标题有点困惑,所以我会解释一下。
我有以下 Controller 方法:

  def password_update
      @op = params[:old_password]
      @np = params[:new_password]
      @cp = params[:confirm_password]

      if @np == @cp
        if !@np.empty?
          if current_user.update_with_password(:current_password=> @op)
              current_user.password = @np
              if current_user.save
                flash[:notice] = "Password Successfully Changed"
                redirect_to settings_path and return 
              end 
          else
            flash[:notice] = "Incorrent Current Password"
            redirect_to change_password_path and return 
          end
        else
          flash[:notice] = "New Password Cannot Be Blank"
        end   
      elsel
        flash[:notice] = "Incorrect Password Confirmation"
      end
      redirect_to change_password_path
    end

其他一切都很好,这意味着我有工作路线和 View ,可以将您带到此方法并在提交表单时调用它。但是,当我尝试正确更改密码时,就会出现错误。顺便说一句,我正在使用设计。当我单击提交时,我退出并显示“您必须登录才能完成此操作”。所以我尝试登录,我当前的密码不起作用。它更改了我的密码(更改为我在表单中设置的密码)!它告诉我我必须登录(当我尝试更改密码时我就是这样)但它仍然会更改它。

欢迎任何帮助,但是,我是新手,非常感谢详细的解释。谢谢!

最佳答案

我相信 Devise wiki 中的这个页面可以回答您的问题:https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-password

这段代码特别

 if @user.update_attributes(params[:user])
   # Sign in the user by passing validation in case his password changed
   sign_in @user, :bypass => true
   redirect_to root_path
 else
   render "edit"
 end

绕过选项似乎也很好命名。希望这可以帮助。干杯

关于ruby-on-rails - 如何通过设计和更新绕过辞职,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11111263/

相关文章:

ruby-on-rails - HAML:表格列的宽度不起作用

c# - 错误 (407) "Proxy Authentication Required."

django - drf django rest auth如何过期或删除 token ?

mysql - 使用 devise 和 activeadmin 设置新的 Rails 应用程序时,schema.rb 最终为空

ruby-on-rails - 设计登录失败消息

ruby-on-rails - SQLite3::ConstraintException:列电子邮件不是唯一的

ruby-on-rails - 如何测试内容是否可见,而不是被 Capybara/Selenium 中的滚动条隐藏

ruby-on-rails - 计划作业的 Resque Scheduler 插件不起作用

jquery - Rails 3.1,jQuery UI 不加载

asp.net - IIS Windows 身份验证 401 未经授权