useradd.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Elgg add action
  4. *
  5. * @package Elgg
  6. * @subpackage Core
  7. */
  8. elgg_make_sticky_form('useradd');
  9. // Get variables
  10. $username = get_input('username');
  11. $password = get_input('password', null, false);
  12. $password2 = get_input('password2', null, false);
  13. $email = get_input('email');
  14. $name = get_input('name');
  15. $admin = get_input('admin');
  16. if (is_array($admin)) {
  17. $admin = $admin[0];
  18. }
  19. // no blank fields
  20. if ($username == '' || $password == '' || $password2 == '' || $email == '' || $name == '') {
  21. register_error(elgg_echo('register:fields'));
  22. forward(REFERER);
  23. }
  24. if (strcmp($password, $password2) != 0) {
  25. register_error(elgg_echo('RegistrationException:PasswordMismatch'));
  26. forward(REFERER);
  27. }
  28. // For now, just try and register the user
  29. try {
  30. $guid = register_user($username, $password, $name, $email, TRUE);
  31. if ($guid) {
  32. $new_user = get_entity($guid);
  33. if ($new_user && $admin && elgg_is_admin_logged_in()) {
  34. $new_user->makeAdmin();
  35. }
  36. elgg_clear_sticky_form('useradd');
  37. $new_user->admin_created = TRUE;
  38. // @todo ugh, saving a guid as metadata!
  39. $new_user->created_by_guid = elgg_get_logged_in_user_guid();
  40. $subject = elgg_echo('useradd:subject', array(), $new_user->language);
  41. $body = elgg_echo('useradd:body', array(
  42. $name,
  43. elgg_get_site_entity()->name,
  44. elgg_get_site_entity()->url,
  45. $username,
  46. $password,
  47. ), $new_user->language);
  48. notify_user($new_user->guid, elgg_get_site_entity()->guid, $subject, $body);
  49. system_message(elgg_echo("adduser:ok", array(elgg_get_site_entity()->name)));
  50. } else {
  51. register_error(elgg_echo("adduser:bad"));
  52. }
  53. } catch (RegistrationException $r) {
  54. register_error($r->getMessage());
  55. }
  56. forward(REFERER);