1
我试图更改用户密码并成功更改,但它不会让我做任何事后因为用户未经授权...我可能错过了一个重新验证它们的部分。在设计中更改用户密码
这是我的代码来更新自己的密码
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
我可以更新密码,但有麻烦再次访问应用程序,因为用户成为非法。
谢谢
我正准备和wiki一样,如果'@ user.update(user_params)'......进入else @Brian – Walker
听起来像'update'失败然后。控制台上是否有任何内容显示阻止更新的内容?或者,您可以查看else子句中的@ user.errors.full_messages,看看发生了什么。 – Brian
布赖恩,我在我的用户控制器中这样做,我只注意到我在我的路线'devise_for:users,:controllers => {:sessions =>“api/v1/sessions”,密码:'api/v1 /密码'},::path_prefix =>'api/v1''这是否意味着我应该在其中一个控制器或其他东西? – Walker