Reputation: 1147
I'm trying to change a users password and it successfully changes but it doesn't let me do anything afterwards because the user becomes unauthorized... I'm probably missing a piece that reauthenticates them.
This is my code to update their password
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
I can update the password but have trouble accessing the app again because the user becomes unauthorized.
Thank you
Upvotes: 1
Views: 3176