eZ Community » Forums » Developer » Modify user login before registration
expandshrink

Modify user login before registration

Modify user login before registration

Friday 08 June 2012 10:51:05 am - 4 replies

Hi,

When a user is registering, I need to modify the login that he has chosen, before the validation of inputs.

I tried to create a custom edit handler but it doesn't seem to work :

<?php
    function validateInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters ) {

        $validation = array( 'is_valid' => true, 'warnings' => array() );

        if ( $module->isCurrentAction( 'Publish' ) && $class->Identifier == 'user' && $editVersion == 1 ) {

            foreach ( $contentObjectAttributes as $contentObjectAttribute ) {

                if ( $contentObjectAttribute->ContentClassAttributeIdentifier == 'user_account' ) {

                    $attContent = $contentObjectAttribute->content();
                    $attContent->setAttribute( 'login', 'MyLogin' );
                    $attContent->store();
                    $contentObjectAttribute->setContent( $attContent );
                    $contentObjectAttribute->store();
                }
            }
        }

        return $validation;
    }
}
?>

I tried with fetchInput() method too, but no result..

I need to do that because today, users fill the login field with their "person number", what I change by to their "contract number", after publishing. But the problem is that some "person numbers" are the same as "contract numbers", and eZ Publish says "User already exists".

Is there any way to do this, except javascript ?

Friday 08 June 2012 12:07:14 pm

Hello,

you can try a workflow before or after publish on user objects. But you should care about confirmation mails with this solution. The mail should be sent with the new login value. Maybe you will have to disable the standard confirmation solution and use your own one in the workflow event.

You could also create your own user datatype by copying eZUserType. With this solution you can do what you need directly in the datatype methods. I can remember that this new datatype should be declared as an user datatype in some configuration file.

Hope it will help.

Friday 08 June 2012 2:37:44 pm

Hi Franck,

Thank you for your response.

I said something wrong before, I don't modify the login after publishing but during registration process, to verify that the "person number" is the good one. If it is not, the registration fails and the register form displays some error. Because of that, I can't use workflow to do the job.

Develop a new datatype would be probably the best solution, but I'm afraid that it could be dangerous for all already registered users with the default datatype.. I won't do it for this project but I'll remind me this solution for following ones.

I'm going to chose the less intrusive way (but definitely not the best), the javascript way, which modify the login field when the form is submitted.

The chance that a user who doesn't have javascript has a "personal number" equal to an existing login, is really really low.

Saturday 09 June 2012 10:49:46 pm

Well, you could also put your own logic in place in a module and handle the user/register yourself:

 

You could do the whole registration process in a registration module all of your own (using user/register.php as your starting point) and hide the differences from user with an apache rewite (user/register -> yourmodule/register)

Monday 11 June 2012 12:02:56 am

Hi David,

I actually created a new register module based on default one, that modify the login, but it still the datatype validation before, which checks if the same login already exists.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu