Skip to content

Instantly share code, notes, and snippets.

@arturo-c
Created October 10, 2011 19:23
Show Gist options
  • Save arturo-c/1276266 to your computer and use it in GitHub Desktop.
Save arturo-c/1276266 to your computer and use it in GitHub Desktop.
function _apci_api_user_create($firstname, $lastname, $email, $gender, $birthday, $password = NULL) {
$account = array(
'mail' => $email,
'field_firstname' => array(array('value' => $firstname)),
'field_lastname' => array(array('value' => $lastname)),
'field_user_gender' => array(array('value' => (strtolower($gender) == 'm') ? 1 : 2)),
'field_birth_date' => array(array('value' => array(
'month' => $birthday['month'],
'hour' => '0',
'minute' => '0',
'second' => '0',
'day' => $birthday['day'],
'year' => $birthday['year'],
))),
'pass' => $password,
// Send welcome email.
// 'notify' => 1,
// Force password change on first login.
// 'force_password_change' => '1',
);
module_load_include('inc', 'user', 'user.pages');
// register a new user
$form_state['values'] = $account;
$form_state['values']['pass'] = array(
'pass1' => $account['pass'],
'pass2' => $account['pass'],
);
$form_state['values']['op'] = t('Create new account');
// Use anonymous to register users.
global $user;
$user_logged = $user;
$user = drupal_anonymous_user();
// execute the register form
drupal_execute('user_register', $form_state);
$user = $user_logged;
// Error if needed.
if ($errors = form_get_errors()) {
return services_error(implode(" ", $errors), 406, array('form_errors' => $errors));
} else {
$user2 = array('uid' => $form_state['user']->uid);
if ($uri = services_resource_uri(array('user', $user2['uid']))) {
$user2['uri'] = $uri;
}
$user = $user2;
}
$user = $form_state['user'];
uuid_user('load', $edit, $user, NULL);
return _apci_api_user_retrieve($user->uuid, '*');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment