registration error...when user makes an error user is told email is sent

Using the default registration, should a user for example, make a mistake on entering their password ( passwords do not match, or do not enter a password ) when the submit the form they get a new page which has in the upper right corner that the passwords do not match ( or whatever the error is ) and also the main page content states an email has been sent for them to verify their account. The user is not created but an email is sent. I found my own solution to fix the problem. As I am NOT on github I did not post the issue.

Here is my solution ( file is actions/register.php ):

 

<?php
/**
 * Elgg registration action
 *
 * @package Elgg.Core
 * @subpackage User.Account
 */

elgg_make_sticky_form('register');

// 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');

$registrationError = false;

if (elgg_get_config('allow_registration')) {
    try 
    {
        if (trim($password) == "" || trim($password2) == "") {
            $registrationError = true;
            throw new RegistrationException(elgg_echo('RegistrationException:EmptyPassword'));
        }

        if (strcmp($password, $password2) != 0) {
            $registrationError = true;
            throw new RegistrationException(elgg_echo('RegistrationException:PasswordMismatch'));
        }
        
        if( $registrationError == false )
        {

            $guid = register_user( $username, $password, $name, $email );

            if ($guid)
            {
                $new_user = get_entity($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
                );

                // @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');

                if ($new_user->enabled == "yes")
                {
                    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();
            }
            else
            {
                register_error(elgg_echo("registerbad"));
            }

        }
    }
    catch (RegistrationException $r)
    {
        register_error($r->getMessage());
    }
}
else
{
    register_error(elgg_echo('registerdisabled'));
}

forward(REFERER);

  • It doesn't look like something that could possibly be a valid solution. You might want to brush up your knowledge about the way Exceptions work.

    I won't look into replicating it today. We obviously assume that you do not use any 3rd party plugins when you say that you use "default registration", right?

  • I am still trying to learn elgg. I have only been working on this on and off for a week! The solution I gave is just a temp work around that works. The trouble is the script does not work the way it should and I needed a solution. When the exception occurred it should have kept the email sent message from displaying. So, am I the only one with this issue?

    I am using the default registration that comes with the download. So, no to 3rd party plugins. The only plugins are the ones that came with the download.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking