PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/elgg/actions/register.php

https://github.com/brettp/Elgg-pagodabox
PHP | 79 lines | 47 code | 13 blank | 19 comment | 11 complexity | 03a65c28e162ffe487e847a37ae657f0 MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-2.1, BSD-3-Clause
  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');
  12. $password2 = get_input('password2');
  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, false, $friend_guid, $invitecode);
  26. if ($guid) {
  27. elgg_clear_sticky_form('register');
  28. $new_user = get_entity($guid);
  29. // allow plugins to respond to self registration
  30. // note: To catch all new users, even those created by an admin,
  31. // register for the create, user event instead.
  32. // only passing vars that aren't in ElggUser.
  33. $params = array(
  34. 'user' => $new_user,
  35. 'password' => $password,
  36. 'friend_guid' => $friend_guid,
  37. 'invitecode' => $invitecode
  38. );
  39. // @todo should registration be allowed no matter what the plugins return?
  40. if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) {
  41. $new_user->delete();
  42. // @todo this is a generic messages. We could have plugins
  43. // throw a RegistrationException, but that is very odd
  44. // for the plugin hooks system.
  45. throw new RegistrationException(elgg_echo('registerbad'));
  46. }
  47. system_message(elgg_echo("registerok", array(elgg_get_site_entity()->name)));
  48. // if exception thrown, this probably means there is a validation
  49. // plugin that has disabled the user
  50. try {
  51. login($new_user);
  52. } catch (LoginException $e) {
  53. // do nothing
  54. }
  55. // Forward on success, assume everything else is an error...
  56. forward();
  57. } else {
  58. register_error(elgg_echo("registerbad"));
  59. }
  60. } catch (RegistrationException $r) {
  61. register_error($r->getMessage());
  62. }
  63. } else {
  64. register_error(elgg_echo('registerdisabled'));
  65. }
  66. forward(REFERER);