I have a problem and can't seem to find the answer. I'm creating a user via a rest service and it's not creating a user profile along with it. I'm not sure how to even create the profile. our user profiles have custom fields that i can pull with my user_get, but when i try to create a user with just a blank profile, it doesn't like it.
any help would be appreciated
function user_services_create_user() {
$user_name = $input['user_name'];
//the users email address
$email = $input['email'];
if(array_key_exists('password', $input)){
$password = $input['password'];
}
else {
$password = user_password(8);
}
//set up the user fields
$fields = array(
'name' => $user_name,
'mail' => $email,
'pass' => $password,
'status' => 1,
);
//the first parameter is left blank so a new user is created
$user_account = user_save('', $fields);
if(!empty($user_account) && $user_account->uid != '') {
user_services_send_response('New user has been successfully created', 1, 200, $user_account);
}
else {
user_services_send_response('New user cannot be created. Please try again later', 0);
}
}
Changed Code:
function user_services_create_user() {
//the user name of the new user
$user_name = $input['user_name'];
//the users email address
$email = $input['email'];
if(array_key_exists('password', $input)){
$password = $input['password'];
}
else {
$password = user_password(8);
}
user_services_check_user($input);
//set up the user fields
$fields = array(
'name' => $user_name,
'mail' => $email,
'pass' => $password,
'status' => 1,
);
//the first parameter is left blank so a new user is created
$user_account = user_save('', $fields);
if(!empty($user_account) && $user_account->uid != '') {
$node = new stdClass();
$node->uid = $user_account->uid;
$node->type='profile';
$node->title=$user_account->name;
$node->name=$user_account->name;
$node->field_receipt_suppress_name[0]['value'] = user_fill_value_from_request('receipt_suppress_name');
$node->field_receipt_suppress_points[0]['value'] = user_fill_value_from_request('receipt_suppress_points');
$node->field_phone_number[0]['value'] = user_fill_value_from_request('phone_number');
$node->field_first_name[0]['value'] = user_fill_value_from_request('first_name');
$node->field_last_name[0]['value'] = user_fill_value_from_request('last_name');
$node->field_user_phone_number[0]['value'] = user_fill_value_from_request('user_phone_number');
$node->field_points[0]['value'] = user_fill_value_from_request('points');
$node->field_date_points_last_checked[0]['value'] = user_fill_value_from_request('date_points_last_checked');
$node->field_last_reward_issued_store[0]['nid'] = user_fill_value_from_request('last_reward_issued_store');
$node->field_last_reward_issued_date[0]['value'] = user_fill_value_from_request('last_reward_issued_date');
$node->field_last_reward_redeemed[0]['value'] = user_fill_value_from_request('last_reward_redeemed');
$node->field_last_reward_redeemed_store[0]['nid'] = user_fill_value_from_request('last_reward_redeemed_store');
$node->field_last_reward_redeemed_date[0]['value'] = user_fill_value_from_request('last_reward_redeemed_date');
node_save($node);
user_services_send_response('New user has been successfully created', 1, 200, $user_account);
}
else {
user_services_send_response('New user cannot be created. Please try again later', 0);
}
}