register.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Elgg registration action
  4. *
  5. * @package Elgg.Core
  6. * @subpackage User.Account
  7. */
  8. elgg_make_sticky_form('register');
  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. $friend_guid = (int) get_input('friend_guid', 0);
  16. $invitecode = get_input('invitecode');
  17. if (elgg_get_config('allow_registration')) {
  18. try {
  19. if (trim($password) == "" || trim($password2) == "") {
  20. throw new RegistrationException(elgg_echo('RegistrationException:EmptyPassword'));
  21. }
  22. if (strcmp($password, $password2) != 0) {
  23. throw new RegistrationException(elgg_echo('RegistrationException:PasswordMismatch'));
  24. }
  25. $guid = register_user($username, $password, $name, $email);
  26. if ($guid) {
  27. $new_user = get_entity($guid);
  28. // allow plugins to respond to self registration
  29. // note: To catch all new users, even those created by an admin,
  30. // register for the create, user event instead.
  31. // only passing vars that aren't in ElggUser.
  32. $params = array(
  33. 'user' => $new_user,
  34. 'password' => $password,
  35. 'friend_guid' => $friend_guid,
  36. 'invitecode' => $invitecode
  37. );
  38. // @todo should registration be allowed no matter what the plugins return?
  39. if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) {
  40. $ia = elgg_set_ignore_access(true);
  41. $new_user->delete();
  42. elgg_set_ignore_access($ia);
  43. // @todo this is a generic messages. We could have plugins
  44. // throw a RegistrationException, but that is very odd
  45. // for the plugin hooks system.
  46. throw new RegistrationException(elgg_echo('registerbad'));
  47. }
  48. elgg_clear_sticky_form('register');
  49. if ($new_user->enabled == "yes") {
  50. system_message(elgg_echo("registerok", array(elgg_get_site_entity()->name)));
  51. // if exception thrown, this probably means there is a validation
  52. // plugin that has disabled the user
  53. try {
  54. login($new_user);
  55. } catch (LoginException $e) {
  56. // do nothing
  57. }
  58. }
  59. // Forward on success, assume everything else is an error...
  60. forward();
  61. } else {
  62. register_error(elgg_echo("registerbad"));
  63. }
  64. } catch (RegistrationException $r) {
  65. register_error($r->getMessage());
  66. }
  67. } else {
  68. register_error(elgg_echo('registerdisabled'));
  69. }
  70. forward(REFERER);