Elgg  Version 1.9
register.php
Go to the documentation of this file.
1 <?php
9 elgg_make_sticky_form('register');
10 
11 // Get variables
12 $username = get_input('username');
13 $password = get_input('password', null, false);
14 $password2 = get_input('password2', null, false);
15 $email = get_input('email');
16 $name = get_input('name');
17 $friend_guid = (int) get_input('friend_guid', 0);
18 $invitecode = get_input('invitecode');
19 
20 if (elgg_get_config('allow_registration')) {
21  try {
22  if (trim($password) == "" || trim($password2) == "") {
23  throw new RegistrationException(elgg_echo('RegistrationException:EmptyPassword'));
24  }
25 
26  if (strcmp($password, $password2) != 0) {
27  throw new RegistrationException(elgg_echo('RegistrationException:PasswordMismatch'));
28  }
29 
31 
32  if ($guid) {
33  $new_user = get_entity($guid);
34 
35  // allow plugins to respond to self registration
36  // note: To catch all new users, even those created by an admin,
37  // register for the create, user event instead.
38  // only passing vars that aren't in ElggUser.
39  $params = array(
40  'user' => $new_user,
41  'password' => $password,
42  'friend_guid' => $friend_guid,
43  'invitecode' => $invitecode
44  );
45 
46  // @todo should registration be allowed no matter what the plugins return?
47  if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) {
49  $new_user->delete();
51  // @todo this is a generic messages. We could have plugins
52  // throw a RegistrationException, but that is very odd
53  // for the plugin hooks system.
54  throw new RegistrationException(elgg_echo('registerbad'));
55  }
56 
57  elgg_clear_sticky_form('register');
58 
59  if ($new_user->enabled == "yes") {
60  system_message(elgg_echo("registerok", array(elgg_get_site_entity()->name)));
61 
62  // if exception thrown, this probably means there is a validation
63  // plugin that has disabled the user
64  try {
65  login($new_user);
66  } catch (LoginException $e) {
67  // do nothing
68  }
69  }
70 
71  // Forward on success, assume everything else is an error...
72  forward();
73  } else {
74  register_error(elgg_echo("registerbad"));
75  }
76  } catch (RegistrationException $r) {
77  register_error($r->getMessage());
78  }
79 } else {
80  register_error(elgg_echo('registerdisabled'));
81 }
82 
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
elgg_get_site_entity($site_guid=0)
Get an ElggSite entity (default is current site)
Definition: sites.php:18
$password2
Definition: register.php:14
$r
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
$invitecode
Definition: register.php:18
elgg_clear_sticky_form($form_name)
Clear the sticky form cache.
Definition: input.php:171
$friend_guid
Definition: register.php:17
$e
Definition: metadata.php:12
$name
Definition: register.php:16
$ia
Definition: upgrade.php:26
$guid
Removes an admin notice.
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
$email
Definition: register.php:15
register_user($username, $password, $name, $email, $allow_multiple_emails=false)
Registers a user, returning false if the username already exists.
Definition: users.php:653
$params
Definition: login.php:72
$password
Definition: register.php:13
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_set_ignore_access($ignore=true)
Set if Elgg&#39;s access system should be ignored.
Definition: access.php:43
const REFERER
Definition: elgglib.php:2162
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
Definition: elgglib.php:925
login(ElggUser $user, $persistent=false)
Logs in a specified ElggUser.
Definition: sessions.php:305
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
$username
Definition: register.php:12
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
elgg_make_sticky_form($form_name)
Load all the GET and POST variables into the sticky form cache.
Definition: input.php:144
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604