function _user_resource_create in Services 6.3
Same name and namespace in other branches
- 7.3 resources/user_resource.inc \_user_resource_create()
Create a new user.
This function uses drupal_execute() and as such exepects all input to match the submitting form in question.
Parameters
$account: A object containing account information. The $account object should contain, at minimum, the following properties:
- name (user name)
- mail (email address)
- pass (plain text unencrypted password)
These properties can be passed but are optional
- status (0 for blocked, otherwise will be active by default)
- notify (1 to notify user of new account, will not notify by default)
Roles can be passed in a roles property which is an associative array formatted with '<role id>' => '<role id>', not including the authenticated user role, which is given by default.
Return value
The user object of the newly created user.
1 string reference to '_user_resource_create'
- _user_resource_definition in resources/
user_resource.inc - @file This file will define the resources for dealing with the user object
File
- resources/
user_resource.inc, line 228 - This file will define the resources for dealing with the user object
Code
function _user_resource_create($account) {
// Adds backwards compatability with regression fixed in #1083242
$account = _services_arg_value($account, 'account');
// Load the required includes for saving profile information
// with drupal_execute().
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'] = variable_get('services_user_create_button_resource_create', t('Create new account'));
// execute the register form
drupal_execute('user_register', $form_state);
// Error if needed.
if ($errors = form_get_errors()) {
return services_error(implode(" ", $errors), 406, array(
'form_errors' => $errors,
));
}
else {
$user = array(
'uid' => $form_state['user']->uid,
);
if ($uri = services_resource_uri(array(
'user',
$user['uid'],
))) {
$user['uri'] = $uri;
}
return $user;
}
}