aboutsummaryrefslogtreecommitdiff
path: root/actions/register.php
diff options
context:
space:
mode:
Diffstat (limited to 'actions/register.php')
-rw-r--r--actions/register.php141
1 files changed, 70 insertions, 71 deletions
diff --git a/actions/register.php b/actions/register.php
index 5c69624b3..73926232c 100644
--- a/actions/register.php
+++ b/actions/register.php
@@ -1,81 +1,80 @@
<?php
+/**
+ * Elgg registration action
+ *
+ * @package Elgg.Core
+ * @subpackage User.Account
+ */
- /**
- * Elgg registration action
- *
- * @package Elgg
- * @subpackage Core
+elgg_make_sticky_form('register');
- * @author Curverider Ltd
+// Get variables
+$username = get_input('username');
+$password = get_input('password', null, false);
+$password2 = get_input('password2', null, false);
+$email = get_input('email');
+$name = get_input('name');
+$friend_guid = (int) get_input('friend_guid', 0);
+$invitecode = get_input('invitecode');
- * @link http://elgg.org/
- */
+if (elgg_get_config('allow_registration')) {
+ try {
+ if (trim($password) == "" || trim($password2) == "") {
+ throw new RegistrationException(elgg_echo('RegistrationException:EmptyPassword'));
+ }
+
+ if (strcmp($password, $password2) != 0) {
+ throw new RegistrationException(elgg_echo('RegistrationException:PasswordMismatch'));
+ }
+
+ $guid = register_user($username, $password, $name, $email, false, $friend_guid, $invitecode);
+
+ if ($guid) {
+ $new_user = get_entity($guid);
- require_once(dirname(dirname(__FILE__)) . "/engine/start.php");
- global $CONFIG;
-
- action_gatekeeper();
+ // allow plugins to respond to self registration
+ // note: To catch all new users, even those created by an admin,
+ // register for the create, user event instead.
+ // only passing vars that aren't in ElggUser.
+ $params = array(
+ 'user' => $new_user,
+ 'password' => $password,
+ 'friend_guid' => $friend_guid,
+ 'invitecode' => $invitecode
+ );
- // Get variables
- $username = get_input('username');
- $password = get_input('password');
- $password2 = get_input('password2');
- $email = get_input('email');
- $name = get_input('name');
- $friend_guid = (int) get_input('friend_guid',0);
- $invitecode = get_input('invitecode');
-
- $admin = get_input('admin');
- if (is_array($admin)) $admin = $admin[0];
-
-
- if (!$CONFIG->disable_registration)
- {
- // For now, just try and register the user
-
+ // @todo should registration be allowed no matter what the plugins return?
+ if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) {
+ $ia = elgg_set_ignore_access(true);
+ $new_user->delete();
+ elgg_set_ignore_access($ia);
+ // @todo this is a generic messages. We could have plugins
+ // throw a RegistrationException, but that is very odd
+ // for the plugin hooks system.
+ throw new RegistrationException(elgg_echo('registerbad'));
+ }
+
+ elgg_clear_sticky_form('register');
+ system_message(elgg_echo("registerok", array(elgg_get_site_entity()->name)));
+
+ // if exception thrown, this probably means there is a validation
+ // plugin that has disabled the user
try {
- if (
- (
- (trim($password)!="") &&
- (strcmp($password, $password2)==0)
- ) &&
- ($guid = register_user($username, $password, $name, $email, false, $friend_guid, $invitecode))
- ) {
-
- $new_user = get_entity($guid);
- if (($guid) && ($admin))
- {
- admin_gatekeeper(); // Only admins can make someone an admin
- $new_user->admin = 'yes';
- }
-
- // Send user validation request on register only
- global $registering_admin;
- if (!$registering_admin)
- request_user_validation($guid);
-
- if (!$new_user->admin)
- $new_user->disable('new_user', false); // Now disable if not an admin
- // Don't do a recursive disable. Any entities owned by the user at this point
- // are products of plugins that
-
- system_message(sprintf(elgg_echo("registerok"),$CONFIG->sitename));
-
- forward(); // Forward on success, assume everything else is an error...
- } else {
- register_error(elgg_echo("registerbad"));
- }
- } catch (RegistrationException $r) {
- register_error($r->getMessage());
+ login($new_user);
+ } catch (LoginException $e) {
+ // do nothing
}
+
+ // Forward on success, assume everything else is an error...
+ forward();
+ } else {
+ register_error(elgg_echo("registerbad"));
}
- else
- register_error(elgg_echo('registerdisabled'));
-
- $qs = explode('?',$_SERVER['HTTP_REFERER']);
- $qs = $qs[0];
- $qs .= "?u=" . urlencode($username) . "&e=" . urlencode($email) . "&n=" . urlencode($name) . "&friend_guid=" . $friend_guid;
-
- forward($qs);
+ } catch (RegistrationException $r) {
+ register_error($r->getMessage());
+ }
+} else {
+ register_error(elgg_echo('registerdisabled'));
+}
-?> \ No newline at end of file
+forward(REFERER);