Guest User

Untitled

a guest
Aug 14th, 2018
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. function _apci_api_user_create($firstname, $lastname, $email, $gender, $birthday, $password = NULL) {
  2. $account = array(
  3. 'mail' => $email,
  4. 'field_firstname' => array(array('value' => $firstname)),
  5. 'field_lastname' => array(array('value' => $lastname)),
  6. 'field_user_gender' => array(array('value' => (strtolower($gender) == 'm') ? 1 : 2)),
  7. 'field_birth_date' => array(array('value' => array(
  8. 'month' => $birthday['month'],
  9. 'hour' => '0',
  10. 'minute' => '0',
  11. 'second' => '0',
  12. 'day' => $birthday['day'],
  13. 'year' => $birthday['year'],
  14. ))),
  15. 'pass' => $password,
  16. // Send welcome email.
  17. // 'notify' => 1,
  18. // Force password change on first login.
  19. // 'force_password_change' => '1',
  20. );
  21. module_load_include('inc', 'user', 'user.pages');
  22.  
  23. // register a new user
  24. $form_state['values'] = $account;
  25. $form_state['values']['pass'] = array(
  26. 'pass1' => $account['pass'],
  27. 'pass2' => $account['pass'],
  28. );
  29. $form_state['values']['op'] = t('Create new account');
  30.  
  31. // Use anonymous to register users.
  32. global $user;
  33. $user_logged = $user;
  34. $user = drupal_anonymous_user();
  35. // execute the register form
  36. drupal_execute('user_register', $form_state);
  37. $user = $user_logged;
  38. // Error if needed.
  39. if ($errors = form_get_errors()) {
  40. return services_error(implode(" ", $errors), 406, array('form_errors' => $errors));
  41. } else {
  42. $user2 = array('uid' => $form_state['user']->uid);
  43. if ($uri = services_resource_uri(array('user', $user2['uid']))) {
  44. $user2['uri'] = $uri;
  45. }
  46. $user = $user2;
  47. }
  48. $user = $form_state['user'];
  49. uuid_user('load', $edit, $user, NULL);
  50. return _apci_api_user_retrieve($user->uuid, '*');
  51. }
Add Comment
Please, Sign In to add comment