diff options
Diffstat (limited to 'actions/register.php')
-rw-r--r--[-rwxr-xr-x] | actions/register.php | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/actions/register.php b/actions/register.php index ff5e495b5..73926232c 100755..100644 --- a/actions/register.php +++ b/actions/register.php @@ -2,65 +2,68 @@ /** * Elgg registration action * - * @package Elgg - * @subpackage Core - * @author Curverider Ltd - * @link http://elgg.org/ + * @package Elgg.Core + * @subpackage User.Account */ -global $CONFIG; -error_log("register user foaf!"); +elgg_make_sticky_form('register'); + // Get variables $username = get_input('username'); -$password = get_input('password'); -$password2 = get_input('password2'); +$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); +$friend_guid = (int) get_input('friend_guid', 0); $invitecode = get_input('invitecode'); -$exponent = get_input('key_exp'); -$modulus = get_input('key_mod'); -$webid = get_input('key_webid'); -if (!($exponent && $modulus && $webid)) - forward(); +if (elgg_get_config('allow_registration')) { + try { + if (trim($password) == "" || trim($password2) == "") { + throw new RegistrationException(elgg_echo('RegistrationException:EmptyPassword')); + } -$admin = get_input('admin'); -if (is_array($admin)) { - $admin = $admin[0]; -} + if (strcmp($password, $password2) != 0) { + throw new RegistrationException(elgg_echo('RegistrationException:PasswordMismatch')); + } -if (!$CONFIG->disable_registration) { -// For now, just try and register the user - try { $guid = register_user($username, $password, $name, $email, false, $friend_guid, $invitecode); - if (((trim($password) != "") && (strcmp($password, $password2) == 0)) && ($guid)) { + + if ($guid) { $new_user = get_entity($guid); -error_log("register user foaf2!"); - elgg_set_ignore_access(true); - elgg_foafssl_createkey($modulus, $exponent, $new_user, $webid, $name." register cert"); - elgg_set_ignore_access(false); - if (($guid) && ($admin)) { - // Only admins can make someone an admin - admin_gatekeeper(); - $new_user->makeAdmin(); - } - // Send user validation request on register only - global $registering_admin; - if (!$registering_admin) { - request_user_validation($guid); - } + // 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 + ); - if (!$new_user->isAdmin()) { - // 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 hook into create user and might need - // access to the entities. - $new_user->disable('new_user', false); + // @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')); } - system_message(sprintf(elgg_echo("registerok"),$CONFIG->sitename)); + 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 { + login($new_user); + } catch (LoginException $e) { + // do nothing + } // Forward on success, assume everything else is an error... forward(); @@ -74,8 +77,4 @@ error_log("register user foaf2!"); 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); +forward(REFERER); |