Elgg  Version 2.3
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)) {
48  $ia = elgg_set_ignore_access(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  // set forward url
68  if ($session->has('last_forward_from')) {
69  $forward_url = $session->get('last_forward_from');
70  $forward_source = 'last_forward_from';
71  } else {
72  // forward to main index page
73  $forward_url = '';
74  $forward_source = null;
75  }
76  $params = array('user' => $new_user, 'source' => $forward_source);
77  $forward_url = elgg_trigger_plugin_hook('login:forward', 'user', $params, $forward_url);
79  } catch (LoginException $e) {
80  register_error($e->getMessage());
82  }
83  }
84 
85  // Forward on success, assume everything else is an error...
86  forward();
87  } else {
88  register_error(elgg_echo("registerbad"));
89  }
90  } catch (RegistrationException $r) {
91  register_error($r->getMessage());
92  }
93 } else {
94  register_error(elgg_echo('registerdisabled'));
95 }
96 
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
elgg_get_site_entity($site_guid=0)
Get an entity (default is current site)
Definition: sites.php:18
$password2
Definition: register.php:14
$r
if(!$entity->delete()) $forward_url
Definition: delete.php:37
$invitecode
Definition: register.php:18
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$friend_guid
Definition: register.php:17
$e
Definition: metadata.php:12
elgg_get_session()
Gets Elgg&#39;s session object.
Definition: sessions.php:23
$name
Definition: register.php:16
$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:425
$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:316
$params
Definition: login.php:72
$password
Definition: register.php:13
elgg_set_ignore_access($ignore=true)
Set if Elgg&#39;s access system should be ignored.
Definition: access.php:43
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
const REFERER
Definition: elgglib.php:2123
elgg_make_sticky_form($form_name)
Save form submission data (all GET and POST vars) into a session cache.
Definition: input.php:103
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:826
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:390
$username
Definition: register.php:12
$forward_source
Definition: login.php:21
$site name
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:399
login(\ElggUser $user, $persistent=false)
Logs in a specified .
Definition: sessions.php:320
$session
Definition: login.php:9
elgg_clear_sticky_form($form_name)
Remove form submission data from the session.
Definition: input.php:119
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204