AddEventHandler("main", "OnBeforeUserLogin", "OnBeforeUserLoginHandler");
function OnBeforeUserLoginHandler(&$arFields)
{
if (isset($_POST['USER_LOGIN']))
{
$e = strpos($_POST['USER_LOGIN'], "@");
$filter = '';
if ((int)$e > 0)
{
$filter = Array("EMAIL" => $_POST['USER_LOGIN']);
}
else if (!preg_match('/[^0-9]/', $_POST['USER_LOGIN']))
{
$filter = Array("UF_ID_1C" => $_POST['USER_LOGIN']);
}
if (!empty($filter))
{
$rsUsers = CUser::GetList(($by="id"), ($order="desc"), $filter);
$res = $rsUsers->Fetch();
$arFields["LOGIN"]=$res['LOGIN'];
}
}
} |