I recently created a way to change the current user password, however after saving the record, my UserSession.find returns nil, I tried by writing UserSession.new({...}).save with no luck, any suggestion on how to resolve this issue?
Here is my code, notice that is run through an AJAX request (this is a method under UserSessionController):
def
change_my_password
#print "--------------RECORD: #{current_user_session.record.as_json}-------- #{current_user_session.user.as_json}"
user = current_user
user_email = user.email
user_remember_me = user.remember_created_at
response = {
:success => false,
:message_code => Extjs::MessageCodes::ERROR,
:message => 'Si è verificato un errore',
:total => 0,
:root => []
}
if user.valid_password?(params[:old_password], true)
user.password = params[:new_password]
user.password_confirmation = params[:confirm_password]
response[:message] = 'La nuova password e la conferma non coincidono o sono troppo brevi'
if user.save
response[:success] = true
response[:message_code] = Extjs::MessageCodes::SUCCESS
response[:message] = 'Password modificata con successo'
end
else
response[:message] = 'La password precedente non coincide con quella attualmente in uso'
end
respond_to do |format|
format.extjson { render :json => response }
end
end