Pavel2019-02-08 13:32:59
Pavel, 2019-02-08 13:32:59

1C Bitrix - How to use email instead of login?

How to use email instead of a login when registering so that there are no problems with rights and user groups in the future?
I found a 9-year-old article , is it still relevant or is it possible to do something differently now?
Component: custom registration.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Roman Morenets, 2020-02-09

Adding this code to init.php helped me:

AddEventHandler("main", "OnBeforeUserLogin", array("CCustomHookEvent", "DoBeforeUserLoginHandler"));
class CCustomHookEvent {
        //  Проверяем пришел ли email или login и если email авторизуем по нему
        function DoBeforeUserLoginHandler( &$arFields )
            $userLogin = $_POST["USER_LOGIN"];
            if (isset($userLogin))
                $isEmail = strpos($userLogin,"@");
                if ($isEmail>0)
                    $arFilter = Array("EMAIL"=>$userLogin);
                    $rsUsers = CUser::GetList(($by="id"), ($order="desc"), $arFilter);
                    if($res = $rsUsers->Fetch())
                            $arFields["LOGIN"] = $res["LOGIN"];
        // End 

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question