Bitrix Site Manager

OnBeforeUserSimpleRegister event

bool
event_handler(
 array &arFields,
);

The OnBeforeUserSimpleRegister event fires before a attempt of user simplified registration performed by CUser::SimpleRegister. This can be used to cancel the registration process or redefine fields.

Parameters

ParameterDescription
arFields Array of new user registration fields:
  • PASSWORD - password;
  • CONFIRM_PASSWORD - password confirmation;
  • CHECKWORD - new check word for password change;
  • EMAIL - user e-mail;
  • ACTIVE - active state flag [Y|N];
  • SITE_ID - the ID of default site used for notifications;
  • GROUP_ID - array of user group ID's;
  • USER_IP - user IP address;
  • USER_HOST - user host name.
Using this array, the system adds a user and sends an e-mail message NEW_USER.

Note
All parameters passed to this handler function are references to original variables. Therefore, all changes to parameters made within the handler affect values of the original variables. This allows to add additional user registration fields or define add a LOGIN field (sensible user name - by default, the logis is set to user<new user ID>" after the registration) .

Return Values

To cancel the user registration and terminate the CUser::SimpleRegister method, raise an exception from within the handler using the method $APPLICATION->ThrowException() and return false.

See Also

Example



<?
// file /bitrix/php_interface/init.php
AddEventHandler(
    "main", 
    "OnBeforeUserSimpleRegister", 
    Array("MyClass", 
          "OnBeforeUserSimpleRegisterHandler"), 
    100, 
    $_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/scripts/onbeforeusersimplereg.php"
);
?>

<?
// file /bitrix/php_interface/scripts/onbeforeusersimplereg.php
class MyClass
{
    // create handler "OnBeforeUserSimpleRegister"
    function OnBeforeUserSimpleRegisterHandler(&$arFields)
    {
        if (strpos($arFields["EMAIL"], "@mysite.com")===false)
        {
            global $APPLICATION;
            $APPLICATION->ThrowException("The registration is only possible "
                                         "for e-mail addresses of the domain mysite.com");
            return false;
        }
    }
}
?>