繁体   English   中英

在设计中更改用户密码

[英]Changing user password in devise

我正在尝试更改用户密码,并且成功更改了密码,但是此后我无法做任何事情,因为用户遭到了未授权...我可能丢失了用于重新验证用户密码的内容。

这是我的密码更新密码

def password

    if current_user.valid_password?(params[:current_password])

      current_user.password = params[:new_password]

      if current_user.save
        #sign them in

         #tried doing this to sign them in again but didn't work
          sign_in(:user, current_user)
          response.headers['X-CSRF-Token'] = form_authenticity_token
          response.headers['X-Pyne-Auth'] = current_user.authentication_token

          render :json => {:success => true} and return
        else
          render :json => {:success => false, error: "Unexpected error while trying to save user. Please try again."} and return
      end

    else
      render :json => {:success => false, error: "Your current password is incorrect. Please try again"} and return
    end

  end

我可以更新密码,但是由于用户未经授权而无法再次访问该应用程序。

谢谢

按照Devise Wiki中的建议尝试bypass_sign_in(@user)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM