When trying to update user (custom) fields programatically in drupal 7, I get the weird problem that whenever I do, my password is reset, my user is logged out, and I have to reset password to be able to log-in again.
I have tried a few different things, none seem to work, here's my code.
global $user;
global $language;
$fullUser = user_load($user->uid);
$updateUserParams = array();
$updateUserParams['language'] = $language->language;
$updateUserParams['field_first_name'][LANGUAGE_NONE][0]['value'] = $form_state['values']['firstName'];
$updateUserParams['field_surname'][LANGUAGE_NONE][0]['value'] = $form_state['values']['lastName'];
$year = $form_state['values']['birthdate']['year'];
$month = $form_state['values']['birthdate']['month'];
$day = $form_state['values']['birthdate']['day'];
$birthdate = date( "Y-m-d", strtotime($year.'-'.$month.'-'.$day));
$updateUserParams['field_birthdate'][LANGUAGE_NONE][0]['value'] = $birthdate;
$updateUserParams['gender'][LANGUAGE_NONE][0]['value'] = $form_state['values']['gender'];
$updateUserParams['field_address']['en'][0]['thoroughfare'] = $form_state['values']['street'];
$updateUserParams['field_address']['en'][0]['postal_code'] = $form_state['values']['postalCode'];
$updateUserParams['field_address']['en'][0]['locality'] = $form_state['values']['city'];
$updateUserParams['field_phone'][LANGUAGE_NONE][0]['value'] = $form_state['values']['phone'];
user_save($user, $updateUserParams);
What am I doing wrong?