60 parent::__construct();
65 if (isset(static::$kernelSession[
"SESS_AUTH"][
$name]))
67 return static::$kernelSession[
"SESS_AUTH"][
$name];
75 return (
string)$this->
getContext()->getUserId();
77 case 'APPLICATION_ID':
78 return $this->
getContext()->getApplicationId();
86 static::$kernelSession[
"SESS_AUTH"][
$name] = $value;
91 if (!is_array($this->
GetParam(
"POLICY")))
93 $this->
SetParam(
"POLICY", static::getPolicy($this->
GetID())->getValues());
102 trigger_error(
"Static call CUser::GetID() is deprecated, will be removed soon. Use global \$USER.", E_USER_WARNING);
105 return $USER->GetID();
114 trigger_error(
"Static call CUser::GetLogin() is deprecated, will be removed soon. Use global \$USER.", E_USER_WARNING);
117 return $USER->GetLogin();
126 trigger_error(
"Static call CUser::GetEmail() is deprecated, will be removed soon. Use global \$USER.", E_USER_WARNING);
129 return $USER->GetEmail();
138 trigger_error(
"Static call CUser::GetFullName() is deprecated, will be removed soon. Use global \$USER.", E_USER_WARNING);
141 return $USER->GetFullName();
150 trigger_error(
"Static call CUser::GetFirstName() is deprecated, will be removed soon. Use global \$USER.", E_USER_WARNING);
153 return $USER->GetFirstName();
155 return $this->
GetParam(
"FIRST_NAME");
162 trigger_error(
"Static call CUser::GetLastName() is deprecated, will be removed soon. Use global \$USER.", E_USER_WARNING);
165 return $USER->GetLastName();
167 return $this->
GetParam(
"LAST_NAME");
174 trigger_error(
"Static call CUser::GetSecondName() is deprecated, will be removed soon. Use global \$USER.", E_USER_WARNING);
177 return $USER->GetSecondName();
179 return $this->
GetParam(
"SECOND_NAME");
184 return static::FormatName(CSite::GetNameFormat($bUseBreaks),
186 "TITLE" => $this->
GetParam(
"TITLE"),
225 $originalPassword =
$arFields[
"PASSWORD"] ??
'';
231 $arFields[
"~CHECKWORD_TIME"] =
$DB->CurrentTimeFunction();
244 array_key_exists(
"PERSONAL_PHOTO",
$arFields)
247 !array_key_exists(
"MODULE_ID",
$arFields[
"PERSONAL_PHOTO"])
248 ||
$arFields[
"PERSONAL_PHOTO"][
"MODULE_ID"] ==
''
252 $arFields[
"PERSONAL_PHOTO"][
"MODULE_ID"] =
'main';
255 CFile::SaveForDB(
$arFields,
"PERSONAL_PHOTO",
'main');
261 !array_key_exists(
"MODULE_ID",
$arFields[
"WORK_LOGO"])
262 ||
$arFields[
"WORK_LOGO"][
"MODULE_ID"] ==
''
266 $arFields[
"WORK_LOGO"][
"MODULE_ID"] =
'main';
269 CFile::SaveForDB(
$arFields,
"WORK_LOGO",
'main');
291 "PHONE_NUMBER" =>
$arFields[
"PHONE_NUMBER"],
296 if (
Option::get(
'main',
'use_digest_auth',
'N') ==
'Y')
298 static::UpdateDigest(
$ID, $originalPassword);
302 UserPasswordTable::add([
308 if (
Option::get(
'main',
'user_profile_history') ===
'Y')
325 if (
$ID > 0 && defined(
"BX_COMP_MANAGED_CACHE"))
328 static::clearTagCache(
$ID, $isRealUser);
336 public static function GetDropDownList($strSqlSearch =
"and ACTIVE='Y'", $strSqlOrder =
"ORDER BY ID, NAME, LAST_NAME")
345 " . $helper->getConcatFunction(
"'['",
"ID",
"'] ('",
"LOGIN",
"') '",
"coalesce(NAME,'')",
"' '",
"coalesce(LAST_NAME,'')") .
" as REFERENCE
366 $arOrder = is_array($by) ? $by : [$by =>
$order];
368 static $arFields_m = [
"ID",
"ACTIVE",
"LAST_LOGIN",
"LOGIN",
"EMAIL",
"NAME",
"LAST_NAME",
"SECOND_NAME",
"TIMESTAMP_X",
"PERSONAL_BIRTHDAY",
"IS_ONLINE",
"IS_REAL_USER"];
370 "DATE_REGISTER",
"PERSONAL_PROFESSION",
"PERSONAL_WWW",
"PERSONAL_ICQ",
"PERSONAL_GENDER",
"PERSONAL_PHOTO",
"PERSONAL_PHONE",
"PERSONAL_FAX",
371 "PERSONAL_MOBILE",
"PERSONAL_PAGER",
"PERSONAL_STREET",
"PERSONAL_MAILBOX",
"PERSONAL_CITY",
"PERSONAL_STATE",
"PERSONAL_ZIP",
"PERSONAL_COUNTRY",
"PERSONAL_NOTES",
372 "WORK_COMPANY",
"WORK_DEPARTMENT",
"WORK_POSITION",
"WORK_WWW",
"WORK_PHONE",
"WORK_FAX",
"WORK_PAGER",
"WORK_STREET",
"WORK_MAILBOX",
"WORK_CITY",
"WORK_STATE",
373 "WORK_ZIP",
"WORK_COUNTRY",
"WORK_PROFILE",
"WORK_NOTES",
"ADMIN_NOTES",
"XML_ID",
"LAST_NAME",
"SECOND_NAME",
"STORED_HASH",
"CHECKWORD_TIME",
"EXTERNAL_AUTH_ID",
374 "CONFIRM_CODE",
"LOGIN_ATTEMPTS",
"LAST_ACTIVITY_DATE",
"AUTO_TIME_ZONE",
"TIME_ZONE",
"TIME_ZONE_OFFSET",
"PASSWORD",
"CHECKWORD",
"LID",
"LANGUAGE_ID",
"TITLE",
376 $arFields_all = array_merge($arFields_m,
$arFields);
378 $arSelectFields = [];
379 $online_interval = (array_key_exists(
"ONLINE_INTERVAL",
$arParams) && intval(
$arParams[
"ONLINE_INTERVAL"]) > 0 ?
$arParams[
"ONLINE_INTERVAL"] : static::GetSecondsForLimitOnline());
384 $field = strtoupper($field);
385 if ($field ==
'TIMESTAMP_X' || $field ==
'DATE_REGISTER' || $field ==
'LAST_LOGIN')
387 $arSelectFields[$field] =
$DB->DateToCharFunction(
"U." . $field) .
' ' . $field .
", U." . $field .
' ' . $field .
"_DATE";
389 elseif ($field ==
'PERSONAL_BIRTHDAY')
391 $arSelectFields[$field] =
$DB->DateToCharFunction(
"U.PERSONAL_BIRTHDAY",
"SHORT") .
" PERSONAL_BIRTHDAY, U.PERSONAL_BIRTHDAY PERSONAL_BIRTHDAY_DATE";
393 elseif ($field ==
'IS_ONLINE')
395 $arSelectFields[$field] =
'CASE WHEN U.LAST_ACTIVITY_DATE > ' . $helper->addSecondsToDateTime(
'(-' . $online_interval .
')') .
' THEN \'Y\' ELSE \'N\' END IS_ONLINE';
397 elseif ($field ==
'IS_REAL_USER')
399 $arSelectFields[$field] =
"CASE WHEN U.EXTERNAL_AUTH_ID IN ('" . join(
"', '", static::GetExternalUserTypes()) .
"') THEN 'N' ELSE 'Y' END IS_REAL_USER";
401 elseif (in_array($field, $arFields_all))
403 $arSelectFields[$field] =
'U.' . $field;
407 if (empty($arSelectFields))
409 $arSelectFields[
'*'] =
'U.*';
410 $arSelectFields[
'TIMESTAMP_X'] =
$DB->DateToCharFunction(
"U.TIMESTAMP_X") .
" TIMESTAMP_X";
411 $arSelectFields[
'IS_ONLINE'] =
'CASE WHEN U.LAST_ACTIVITY_DATE > ' . $helper->addSecondsToDateTime(
'(-' . $online_interval .
')') .
' THEN \'Y\' ELSE \'N\' END IS_ONLINE';
412 $arSelectFields[
'DATE_REGISTER'] =
$DB->DateToCharFunction(
"U.DATE_REGISTER") .
" DATE_REGISTER";
413 $arSelectFields[
'LAST_LOGIN'] =
$DB->DateToCharFunction(
"U.LAST_LOGIN") .
" LAST_LOGIN";
414 $arSelectFields[
'PERSONAL_BIRTHDAY'] =
$DB->DateToCharFunction(
"U.PERSONAL_BIRTHDAY",
"SHORT") .
" PERSONAL_BIRTHDAY";
417 static $obUserFieldsSql;
418 if (!isset($obUserFieldsSql))
421 $obUserFieldsSql->
SetEntity(
"USER",
"U.ID");
422 $obUserFieldsSql->obWhere->AddFields([
424 "TABLE_ALIAS" =>
"U",
425 "FIELD_NAME" =>
"U.LAST_NAME",
427 "FIELD_TYPE" =>
"string",
433 $ufSelectFields =
$arParams[
"SELECT"] ?? [];
437 $obUserFieldsSql->SetOrder($arOrder);
438 $arSqlSearch[] = $obUserFieldsSql->GetFilter();
439 $distinct = $obUserFieldsSql->GetDistinct();
457 $key !=
"LOGIN_EQUAL_EXACT"
458 &&
$key !=
"CONFIRM_CODE"
459 &&
$key !=
"!CONFIRM_CODE"
460 &&
$key !=
"LAST_ACTIVITY"
461 &&
$key !=
"!LAST_ACTIVITY"
462 &&
$key !=
"LAST_LOGIN"
463 &&
$key !=
"!LAST_LOGIN"
464 &&
$key !=
"EXTERNAL_AUTH_ID"
465 &&
$key !=
"!EXTERNAL_AUTH_ID"
466 &&
$key !=
"IS_REAL_USER"
469 if ((
string)
$val ==
'' ||
$val ===
"NOT_REF")
474 $match_value_set = array_key_exists(
$key .
"_EXACT_MATCH",
$arFilter);
481 $arSqlSearch[] =
"U.ID > " . intval(
$val);
484 $arSqlSearch[] =
"U.ID <> " . intval(
$val);
486 case "ID_EQUAL_EXACT":
487 $arSqlSearch[] =
"U.ID='" . intval(
$val) .
"'";
490 $arSqlSearch[] =
"U.TIMESTAMP_X >= FROM_UNIXTIME('" .
MkDateTime(
FmtDate(
$val,
"D.M.Y"),
"d.m.Y") .
"')";
493 $arSqlSearch[] =
"U.TIMESTAMP_X <= FROM_UNIXTIME('" .
MkDateTime(
FmtDate(
$val,
"D.M.Y") .
" 23:59:59",
"d.m.Y") .
"')";
495 case "TIMESTAMP_X_1":
496 $arSqlSearch[] =
"U.TIMESTAMP_X >= FROM_UNIXTIME('" .
MkDateTime(
FmtDate(
$val,
"DD.MM.YYYY HH:MI:SS")) .
"')";
498 case "TIMESTAMP_X_2":
499 $arSqlSearch[] =
"U.TIMESTAMP_X <= FROM_UNIXTIME('" .
MkDateTime(
FmtDate(
$val,
"DD.MM.YYYY HH:MI:SS")) .
"')";
502 $arSqlSearch[] =
"U.LAST_LOGIN >= FROM_UNIXTIME('" .
MkDateTime(
FmtDate(
$val,
"D.M.Y"),
"d.m.Y") .
"')";
505 $arSqlSearch[] =
"U.LAST_LOGIN <= FROM_UNIXTIME('" .
MkDateTime(
FmtDate(
$val,
"D.M.Y") .
" 23:59:59",
"d.m.Y") .
"')";
510 $arSqlSearch[] =
"U.LAST_LOGIN IS NULL";
516 $arSqlSearch[] =
"U.LAST_LOGIN IS NOT NULL";
519 case "DATE_REGISTER_1":
520 $arSqlSearch[] =
"U.DATE_REGISTER >= FROM_UNIXTIME('" .
MkDateTime(
FmtDate(
$val,
"D.M.Y"),
"d.m.Y") .
"')";
522 case "DATE_REGISTER_2":
523 $arSqlSearch[] =
"U.DATE_REGISTER <= FROM_UNIXTIME('" .
MkDateTime(
FmtDate(
$val,
"D.M.Y") .
" 23:59:59",
"d.m.Y") .
"')";
526 $arSqlSearch[] = (
$val ==
'Y') ?
"U.ACTIVE='Y'" :
"U.ACTIVE='N'";
534 case "EXTERNAL_AUTH_ID":
537 $arSqlSearch[] =
"U.EXTERNAL_AUTH_ID='" .
$DB->ForSQL(
$val, 255) .
"'";
541 $arSqlSearch[] =
"(U.EXTERNAL_AUTH_ID IS NULL OR U.EXTERNAL_AUTH_ID='')";
544 case "!EXTERNAL_AUTH_ID":
551 foreach (
$val as $authId)
555 $strTmp .= ($strTmp !=
'' ?
',' :
'') .
"'" .
$DB->ForSQL($authId, 255) .
"'";
560 $arSqlSearch[] =
"U.EXTERNAL_AUTH_ID NOT IN (" . $strTmp .
") OR U.EXTERNAL_AUTH_ID IS NULL";
567 $arSqlSearch[] =
"U.EXTERNAL_AUTH_ID <> '" .
$DB->ForSql(
$val, 255) .
"' OR U.EXTERNAL_AUTH_ID IS NULL";
571 $arSqlSearch[] =
"(U.EXTERNAL_AUTH_ID IS NOT NULL AND LENGTH(U.EXTERNAL_AUTH_ID) > 0)";
575 case "LOGIN_EQUAL_EXACT":
576 $arSqlSearch[] =
"U.LOGIN='" .
$DB->ForSql(
$val) .
"'";
579 $arSqlSearch[] =
"U.XML_ID='" .
$DB->ForSql(
$val) .
"'";
584 $arSqlSearch[] =
"U.CONFIRM_CODE='" .
$DB->ForSql(
$val) .
"'";
588 $arSqlSearch[] =
"(U.CONFIRM_CODE IS NULL OR LENGTH(U.CONFIRM_CODE) <= 0)";
591 case "!CONFIRM_CODE":
594 $arSqlSearch[] =
"U.CONFIRM_CODE <> '" .
$DB->ForSql(
$val) .
"'";
598 $arSqlSearch[] =
"(U.CONFIRM_CODE IS NOT NULL AND LENGTH(U.CONFIRM_CODE) > 0)";
603 $arSqlSearch[] =
"U.WORK_COUNTRY=" . intval(
$val);
605 case "PERSONAL_COUNTRY":
606 $arSqlSearch[] =
"U.PERSONAL_COUNTRY=" . intval(
$val);
612 $arSqlSearch[] =
GetFilterQuery(
"U.NAME, U.LAST_NAME, U.SECOND_NAME, U.EMAIL, U.LOGIN",
$val);
618 $arSqlSearch[] =
"U.EMAIL = '" .
$DB->ForSQL(trim(
$val)) .
"'";
622 if (is_numeric(
$val) && intval(
$val) > 0)
629 foreach (
$val as $id)
631 $ar[intval($id)] = intval($id);
634 " INNER JOIN (SELECT DISTINCT UG.USER_ID FROM b_user_group UG
635 WHERE UG.GROUP_ID in (" . implode(
",",
$ar) .
")
636 and (UG.DATE_ACTIVE_FROM is null or UG.DATE_ACTIVE_FROM <= " .
$DB->CurrentTimeFunction() .
")
637 and (UG.DATE_ACTIVE_TO is null or UG.DATE_ACTIVE_TO >= " .
$DB->CurrentTimeFunction() .
")
638 ) UG ON UG.USER_ID=U.ID ";
641 case "PERSONAL_BIRTHDATE_1":
642 $arSqlSearch[] =
"U.PERSONAL_BIRTHDATE>=" .
$DB->CharToDateFunction(
$val);
644 case "PERSONAL_BIRTHDATE_2":
645 $arSqlSearch[] =
"U.PERSONAL_BIRTHDATE<=" .
$DB->CharToDateFunction(
$val .
" 23:59:59");
647 case "PERSONAL_BIRTHDAY_1":
648 $arSqlSearch[] =
"U.PERSONAL_BIRTHDAY>=" .
$DB->CharToDateFunction(
$DB->ForSql(
$val),
"SHORT");
650 case "PERSONAL_BIRTHDAY_2":
651 $arSqlSearch[] =
"U.PERSONAL_BIRTHDAY<=" .
$DB->CharToDateFunction(
$DB->ForSql(
$val),
"SHORT");
653 case "PERSONAL_BIRTHDAY_DATE":
654 $arSqlSearch[] = $helper->formatDate(
'MM-DD',
'U.PERSONAL_BIRTHDAY') .
" = '" .
$DB->ForSql(
$val) .
"'";
659 case "CHECK_SUBORDINATE":
663 foreach (
$val as $grp)
665 $strSubord .=
"," . intval($grp);
667 if (intval(
$arFilter[
"CHECK_SUBORDINATE_AND_OWN"]) > 0)
669 $arSqlSearch[] =
"(U.ID=" . intval(
$arFilter[
"CHECK_SUBORDINATE_AND_OWN"]) .
" OR NOT EXISTS(SELECT 'x' FROM b_user_group UGS WHERE UGS.USER_ID=U.ID AND UGS.GROUP_ID NOT IN (" . $strSubord .
")))";
673 $arSqlSearch[] =
"NOT EXISTS(SELECT 'x' FROM b_user_group UGS WHERE UGS.USER_ID=U.ID AND UGS.GROUP_ID NOT IN (" . $strSubord .
"))";
682 $arSqlSearch[] =
"not exists (SELECT * FROM b_user_group UGNA WHERE UGNA.USER_ID=U.ID AND UGNA.GROUP_ID = 1)";
684 case "LAST_ACTIVITY":
687 $arSqlSearch[] =
"U.LAST_ACTIVITY_DATE IS NULL";
691 $arSqlSearch[] =
"U.LAST_ACTIVITY_DATE > " . $helper->addSecondsToDateTime(-intval(
$val));
694 case "!LAST_ACTIVITY":
697 $arSqlSearch[] =
"U.LAST_ACTIVITY_DATE IS NOT NULL";
700 case "INTRANET_USERS":
701 $arSqlSearch[] =
"U.ACTIVE = 'Y' AND U.LAST_LOGIN IS NOT NULL AND EXISTS(SELECT 'x' FROM b_utm_user UF1, b_user_field F1 WHERE F1.ENTITY_ID = 'USER' AND F1.FIELD_NAME = 'UF_DEPARTMENT' AND UF1.FIELD_ID = F1.ID AND UF1.VALUE_ID = U.ID AND UF1.VALUE_INT IS NOT NULL AND UF1.VALUE_INT <> 0)";
706 $arSqlSearch[] =
"U.EXTERNAL_AUTH_ID NOT IN ('" . join(
"', '", static::GetExternalUserTypes()) .
"') OR U.EXTERNAL_AUTH_ID IS NULL";
710 $arSqlSearch[] =
"U.EXTERNAL_AUTH_ID IN ('" . join(
"', '", static::GetExternalUserTypes()) .
"')";
723 foreach ($arOrder as $field =>
$dir)
725 $field = strtoupper($field);
726 if (strtolower(
$dir) !=
"asc")
731 if ($field ==
"CURRENT_BIRTHDAY")
733 $cur_year = intval(date(
'Y'));
734 $arSelectFields[$field] =
"case
735 when U.PERSONAL_BIRTHDAY is null then '9999-99-99'
736 when " . $helper->formatDate($cur_year .
'-MM-DD',
'U.PERSONAL_BIRTHDAY') .
' < ' . $helper->formatDate(
'YYYY-MM-DD', $helper->addSecondsToDateTime(CTimeZone::GetOffset())) .
" then " . $helper->formatDate(($cur_year + 1) .
'-MM-DD',
'U.PERSONAL_BIRTHDAY') .
"
737 else " . $helper->formatDate($cur_year .
'-MM-DD',
'U.PERSONAL_BIRTHDAY') .
"
738 end CURRENT_BIRTHDAY";
739 $arSqlOrder[$field] =
"CURRENT_BIRTHDAY " .
$dir;
741 elseif ($field ==
"IS_ONLINE")
743 $arSelectFields[$field] =
"case when U.LAST_ACTIVITY_DATE > " . $helper->addSecondsToDateTime(-$online_interval) .
" then 'Y' else 'N' end IS_ONLINE";
744 $arSqlOrder[$field] =
"IS_ONLINE " .
$dir;
746 elseif (in_array($field, $arFields_all))
748 $arSqlOrder[$field] =
"U." . $field .
' ' .
$dir;
750 if ($distinct && !isset($arSelectFields[
'*']) && !isset($arSelectFields[$field]))
752 $arSelectFields[$field] =
'U.' . $field;
755 elseif ($s = $obUserFieldsSql->GetOrder($field))
757 $arSqlOrder[$field] = strtoupper($s) .
' ' .
$dir;
759 if ($distinct && !in_array(
'UF_*', $ufSelectFields) && !in_array($field, $ufSelectFields))
761 $ufSelectFields[] = $field;
769 $arSqlOrder[$field] = $field .
"_ISNULL ASC, " . $field .
' ' .
$dir;
774 $field =
"TIMESTAMP_X";
775 $arSqlOrder[$field] =
"U." . $field .
' ' .
$dir;
776 $arSelectFields[$field] =
'U.TIMESTAMP_X';
779 elseif ($field ==
'FULL_NAME')
781 $arSelectFields[
'LAST_NAME_SRT1'] =
"CASE WHEN U.LAST_NAME IS NULL OR U.LAST_NAME = '' THEN 1 ELSE 0 END LAST_NAME_SRT1";
782 $arSelectFields[
'LAST_NAME_SRT2'] =
"CASE WHEN U.LAST_NAME IS NULL OR U.LAST_NAME = '' THEN '1' ELSE U.LAST_NAME END LAST_NAME_SRT2";
783 $arSelectFields[
'NAME_SRT1'] =
"CASE WHEN U.NAME IS NULL OR U.NAME = '' THEN 1 ELSE 0 END NAME_SRT1";
784 $arSelectFields[
'NAME_SRT2'] =
"CASE WHEN U.NAME IS NULL OR U.NAME = '' THEN '1' ELSE U.NAME END NAME_SRT2";
785 $arSelectFields[
'SECOND_NAME_SRT1'] =
"CASE WHEN U.SECOND_NAME IS NULL OR U.SECOND_NAME = '' THEN 1 ELSE 0 END SECOND_NAME_SRT1";
786 $arSelectFields[
'SECOND_NAME_SRT2'] =
"CASE WHEN U.SECOND_NAME IS NULL OR U.SECOND_NAME = '' THEN '1' ELSE U.SECOND_NAME END SECOND_NAME_SRT2";
787 $arSelectFields[
'LOGIN'] =
"U.LOGIN";
789 $arSqlOrder[$field] =
"LAST_NAME_SRT1 {$dir}, LAST_NAME_SRT2 {$dir}, NAME_SRT1 {$dir}, NAME_SRT2 {$dir}, SECOND_NAME_SRT1 {$dir}, SECOND_NAME_SRT2 {$dir}, U.LOGIN {$dir}";
793 $obUserFieldsSql->SetSelect($ufSelectFields);
794 $userFieldsSelect = $obUserFieldsSql->GetSelect();
797 $sSelect = ($distinct ?
"DISTINCT " :
'')
798 . implode(
', ', $arSelectFields) .
"
799 " . $userFieldsSelect .
"
804 $arRatingInSelect = [];
807 if (preg_match(
'/^RATING_(\d+)$/i', $column,
$matches))
810 if ($ratingId > 0 && !isset($arRatingInSelect[$ratingId]))
812 $sSelect .=
", RR" . $ratingId .
".CURRENT_POSITION IS NULL as RATING_" . $ratingId .
"_ISNULL";
813 $sSelect .=
", RR" . $ratingId .
".CURRENT_VALUE as RATING_" . $ratingId;
814 $sSelect .=
", RR" . $ratingId .
".CURRENT_VALUE as RATING_" . $ratingId .
"_CURRENT_VALUE";
815 $sSelect .=
", RR" . $ratingId .
".PREVIOUS_VALUE as RATING_" . $ratingId .
"_PREVIOUS_VALUE";
816 $sSelect .=
", RR" . $ratingId .
".CURRENT_POSITION as RATING_" . $ratingId .
"_CURRENT_POSITION";
817 $sSelect .=
", RR" . $ratingId .
".PREVIOUS_POSITION as RATING_" . $ratingId .
"_PREVIOUS_POSITION";
819 $strJoin .=
" LEFT JOIN b_rating_results RR" . $ratingId .
"
820 ON RR" . $ratingId .
".RATING_ID=" . $ratingId .
"
821 and RR" . $ratingId .
".ENTITY_TYPE_ID = 'USER'
822 and RR" . $ratingId .
".ENTITY_ID = U.ID ";
824 $arRatingInSelect[$ratingId] = $ratingId;
833 " . $obUserFieldsSql->GetJoin(
"U.ID") .
"
836 " . $strSqlSearch .
"
840 if (!empty($arSqlOrder))
842 $strSqlOrder =
'ORDER BY ' . implode(
', ', $arSqlOrder);
845 $strSql =
"SELECT " . $sSelect . $strFrom . $strSqlOrder;
849 $nTopCount = (int)(
$arParams[
'NAV_PARAMS'][
'nTopCount'] ?? 0);
852 $strSql =
$DB->TopSql($strSql, $nTopCount);
854 if ($userFieldsSelect !=
'')
861 $res_cnt =
$DB->Query(
"SELECT COUNT(" . ($obUserFieldsSql->GetDistinct() ?
'DISTINCT ' :
'') .
"U.ID) as C " . $strFrom);
862 $res_cnt = $res_cnt->Fetch();
864 if ($userFieldsSelect !=
'')
868 $res->NavQuery($strSql, $res_cnt[
"C"],
$arParams[
"NAV_PARAMS"]);
874 if ($userFieldsSelect !=
'')
885 public static function IsOnLine($id, $interval =
null)
897 if (is_null($interval))
899 $interval = static::GetSecondsForLimitOnline();
903 $interval = intval($interval);
906 $interval = static::GetSecondsForLimitOnline();
910 $dbRes =
$DB->Query(
"SELECT 'x' FROM b_user WHERE ID = " . $id .
" AND LAST_ACTIVITY_DATE > " . $helper->addSecondsToDateTime(-$interval));
911 return (
bool)
$dbRes->Fetch();
932 $arr = array_values(array_unique(
$arr));
951 static $groupsCache = [];
953 if ($userID ===
null &&
$USER instanceof
self)
955 $userID = (int)
$USER->getId();
958 $userGroups =
$USER->GetUserGroupArray();
963 $userGroups = static::GetUserGroup($userID);
970 if (isset($groupsCache[$userID]))
972 $result = $groupsCache[$userID];
978 $groupsCache[$userID] =
$result;
986 header(
"WWW-Authenticate: Basic realm=\"{$Realm}\"");
987 if (stristr(php_sapi_name(),
"cgi") !==
false)
989 header(
"Status: 401 Unauthorized");
993 header(
$_SERVER[
"SERVER_PROTOCOL"] .
" 401 Unauthorized");
1001 if (
Option::get(
'main',
'store_password',
'Y') ==
'Y')
1005 $prefix =
Option::get(
'main',
'cookie_name',
'BITRIX_SM');
1006 $login = (string)($_COOKIE[$prefix .
'_UIDL'] ??
'');
1007 $password = (string)($_COOKIE[$prefix .
'_UIDH'] ??
'');
1024 $result_message =
true;
1033 foreach (
GetModuleEvents(
'main',
'OnBeforeUserLoginByHash',
true) as $arEvent)
1039 $result_message = [
"MESSAGE" => $err->GetString() .
"<br>",
"TYPE" =>
"ERROR"];
1044 $result_message = [
"MESSAGE" =>
"Unknown error" .
"<br>",
"TYPE" =>
"ERROR"];
1055 "SELECT U.ID, U.ACTIVE, U.EXTERNAL_AUTH_ID, U.BLOCKED " .
1057 "WHERE U.LOGIN = '" .
$DB->ForSQL(
$arParams[
'LOGIN'], 50) .
"' ";
1061 while (($arUser =
$result->Fetch()))
1066 $bExternal = ($arUser[
"EXTERNAL_AUTH_ID"] !=
'');
1067 $bAllowExternalSave =
Option::get(
'main',
'allow_external_auth_stored_hash',
'N') ==
'Y';
1068 $tempHash = $bExternal && !$bAllowExternalSave;
1077 if ($arUser[
"ACTIVE"] ==
'Y' && $arUser[
"BLOCKED"] !=
'Y')
1084 $result_message = [
"MESSAGE" =>
GetMessage(
"LOGIN_BLOCK") .
"<br>",
"TYPE" =>
"ERROR"];
1096 ->setSpread($spread)
1099 Main\Context::getCurrent()->getResponse()->addCookie($cookie);
1102 $result_message = [
"MESSAGE" =>
GetMessage(
"WRONG_LOGIN") .
"<br>",
"TYPE" =>
"ERROR"];
1107 $arParams[
"RESULT_MESSAGE"] = $result_message;
1109 foreach (
GetModuleEvents(
'main',
'OnAfterUserLoginByHash',
true) as $arEvent)
1114 if ($result_message !==
true &&
Option::get(
'main',
'event_log_login_fail',
'N') ===
'Y')
1124 $arAuth = Main\Context::getCurrent()->getServer()->parseAuthRequest();
1126 foreach (
GetModuleEvents(
'main',
'onBeforeUserLoginByHttpAuth',
true) as $arEvent)
1135 if (isset($arAuth[
"basic"]) && $arAuth[
"basic"][
"username"] !=
'' && $arAuth[
"basic"][
"password"] !=
'')
1140 return $this->
Login($arAuth[
"basic"][
"username"], $arAuth[
"basic"][
"password"]);
1143 elseif (isset($arAuth[
"digest"]) && $arAuth[
"digest"][
"username"] !=
'' &&
Option::get(
'main',
'use_digest_auth',
'N') ==
'Y')
1164 "SELECT U.ID, U.PASSWORD, UD.DIGEST_HA1, U.EXTERNAL_AUTH_ID " .
1165 "FROM b_user U LEFT JOIN b_user_digest UD ON UD.USER_ID=U.ID " .
1166 "WHERE U.LOGIN='" .
$DB->ForSQL($arDigest[
"username"]) .
"' ";
1169 if ($arUser =
$res->Fetch())
1172 $HA2 = md5(
$method .
':' . $arDigest[
'uri']);
1174 if ($arUser[
"EXTERNAL_AUTH_ID"] ==
'' && $arUser[
"DIGEST_HA1"] !=
'')
1177 static::$kernelSession[
"BX_HTTP_DIGEST_ABSENT"] =
false;
1179 $HA1 = $arUser[
"DIGEST_HA1"];
1180 $valid_response = md5($HA1 .
':' . $arDigest[
'nonce'] .
':' . $HA2);
1182 if ($arDigest[
"response"] === $valid_response)
1185 return $this->
Login($arDigest[
"username"], $arUser[
"PASSWORD"],
'N',
'N');
1192 return $this->
Login($arDigest[
"username"], $appPassword[
"PASSWORD"],
'N',
'N');
1195 if ($arUser[
"DIGEST_HA1"] ==
'')
1198 static::$kernelSession[
"BX_HTTP_DIGEST_ABSENT"] =
true;
1203 return [
"MESSAGE" =>
GetMessage(
"USER_AUTH_DIGEST_ERR") .
"<br>",
"TYPE" =>
"ERROR"];
1212 SELECT U.LOGIN, UD.DIGEST_HA1
1213 FROM b_user U LEFT JOIN b_user_digest UD on UD.USER_ID=U.ID
1218 if (defined(
'BX_HTTP_AUTH_REALM'))
1220 $realm = BX_HTTP_AUTH_REALM;
1224 $realm =
"Bitrix Site Manager";
1227 $digest = md5(
$arRes[
"LOGIN"] .
':' . $realm .
':' .
$pass);
1229 if (
$arRes[
"DIGEST_HA1"] ==
'')
1232 $DB->Query(
"insert into b_user_digest (user_id, digest_ha1) values('" .
$ID .
"', '" .
$DB->ForSQL($digest) .
"')");
1237 if (
$arRes[
"DIGEST_HA1"] !== $digest)
1239 $DB->Query(
"update b_user_digest set digest_ha1='" .
$DB->ForSQL($digest) .
"' where user_id=" .
$ID);
1257 $request = Main\Context::getCurrent()->getRequest();
1258 $url = str_replace(
'%',
'%%',
$request->getRequestedPage());
1263 $query = UserHitAuthTable::query()
1264 ->setSelect([
'ID',
'USER_ID',
'HASH',
'VALID_UNTIL'])
1265 ->where(
'USER.ACTIVE',
'Y')
1266 ->where(
'USER.BLOCKED',
'N')
1267 ->where(
'HASH',
$hash)
1268 ->whereExpr(
"%s = left('" . $helper->forSql(
$url) .
"', length(%s))", [
'URL',
'URL'])
1276 if ($hashData =
$query->fetch())
1279 if ($hashData[
'HASH'] ===
$hash)
1281 if ($hashData[
'VALID_UNTIL'] instanceof
DateTime)
1283 if ((
new DateTime())->getTimestamp() > $hashData[
'VALID_UNTIL']->getTimestamp())
1285 UserHitAuthTable::delete($hashData[
'ID']);
1293 ->setUserId($hashData[
"USER_ID"])
1294 ->setHitAuthId($hashData[
"ID"])
1295 ->setMethod(Method::HitHash)
1302 UserHitAuthTable::delete($hashData[
'ID']);
1306 UserHitAuthTable::update($hashData[
'ID'], [
'TIMESTAMP_X' =>
new DateTime()]);
1327 $user_id =
$USER->GetID();
1342 'USER_ID' => $user_id,
1343 'URL' => trim(
$url),
1351 $fields[
'VALID_UNTIL'] = (
new DateTime())->add(
'T' . (
int)$ttl .
'S');
1354 UserHitAuthTable::add(
$fields);
1364 $urlMask = trim($urlMask);
1372 $userID =
$USER->GetID();
1380 $query = UserHitAuthTable::query()
1381 ->setSelect([
'ID',
'HASH',
'VALID_UNTIL'])
1382 ->where(
'URL', $urlMask)
1383 ->where(
'USER_ID', $userID)
1391 if ($hashData =
$query->fetch())
1393 if ($hashData[
'VALID_UNTIL'] instanceof
DateTime)
1395 if ((
new DateTime())->getTimestamp() > $hashData[
'VALID_UNTIL']->getTimestamp())
1397 UserHitAuthTable::delete($hashData[
'ID']);
1402 return $hashData[
'HASH'];
1410 $cleanupDays = (int)
Option::get(
'main',
'hit_auth_cleanup_days', 30);
1411 if ($cleanupDays > 0)
1413 UserHitAuthTable::deleteByFilter([
'<=TIMESTAMP_X' => (
new DateTime())->add(
"-{$cleanupDays}D")]);
1415 return 'CUser::CleanUpHitAuthAgent();';
1422 unset(static::$kernelSession[
"SESS_OPERATIONS"]);
1428 "WHERE U.ID = " .
$context->getUserId();
1432 $strSql .=
" AND U.ACTIVE = 'Y' AND U.BLOCKED <> 'Y' ";
1437 if ($arUser =
$result->Fetch())
1442 "LOGIN" => $arUser[
"LOGIN"],
1443 "EMAIL" => $arUser[
"EMAIL"],
1444 "TITLE" => $arUser[
"TITLE"],
1445 "NAME" => $arUser[
"NAME"] . ($arUser[
"NAME"] ==
'' || $arUser[
"LAST_NAME"] ==
'' ?
'' :
' ') . $arUser[
"LAST_NAME"],
1446 "FIRST_NAME" => $arUser[
"NAME"],
1447 "SECOND_NAME" => $arUser[
"SECOND_NAME"],
1448 "LAST_NAME" => $arUser[
"LAST_NAME"],
1449 "PERSONAL_PHOTO" => $arUser[
"PERSONAL_PHOTO"],
1450 "PERSONAL_GENDER" => $arUser[
"PERSONAL_GENDER"],
1451 "EXTERNAL_AUTH_ID" => $arUser[
"EXTERNAL_AUTH_ID"],
1452 "XML_ID" => $arUser[
"XML_ID"],
1454 "POLICY" => static::getPolicy(
$groups)->getValues(),
1455 "AUTO_TIME_ZONE" => trim((
string)$arUser[
"AUTO_TIME_ZONE"]),
1456 "TIME_ZONE" => $arUser[
"TIME_ZONE"],
1458 "CONTEXT" => json_encode(
$context),
1461 foreach (
$data[
"GROUPS"] as $groupId)
1465 $data[
"ADMIN"] =
true;
1470 static::$kernelSession[
"SESS_AUTH"] =
$data;
1473 $this->admin =
null;
1493 public function Authorize(
$context, $bSave =
false, $bUpdate =
true, $applicationId =
null, $onlyActive =
true)
1502 ->setApplicationId($applicationId)
1508 if ($arUser !==
false)
1511 if ($regenerateIdAfterLogin ===
true)
1516 self::$CURRENT_USER =
false;
1517 $this->justAuthorized =
true;
1523 if (CTimeZone::OptionEnabled())
1525 $timezone = $arUser[
"TIME_ZONE"] ?: CTimeZone::getTzCookie();
1526 if (!empty($timezone))
1529 $tz =
', TIME_ZONE_OFFSET = ' . CTimeZone::calculateOffset($timezone);
1534 if (!empty($_COOKIE[
'BX_USER_ID']) && preg_match(
'/^[0-9a-f]{32}$/', $_COOKIE[
'BX_USER_ID']))
1536 if ($_COOKIE[
'BX_USER_ID'] != $arUser[
'BX_USER_ID'])
1539 $bxUid =
", BX_USER_ID = '" . $_COOKIE[
'BX_USER_ID'] .
"'";
1540 $arUser[
'BX_USER_ID'] = $_COOKIE[
'BX_USER_ID'];
1545 if (empty($arUser[
'LANGUAGE_ID']))
1547 $arUser[
'LANGUAGE_ID'] = LANGUAGE_ID;
1548 $languageId =
", LANGUAGE_ID='" .
$DB->ForSql(LANGUAGE_ID) .
"'";
1554 LAST_LOGIN = " .
$DB->GetNowFunction() .
",
1555 TIMESTAMP_X = TIMESTAMP_X,
1561 ID=" . $arUser[
"ID"]
1564 if ($bSave ||
Option::get(
'main',
'auth_multisite',
'N') ==
'Y')
1577 if (
$context->getStoredAuthId() > 0)
1579 UserStoredAuthTable::update(
$context->getStoredAuthId(), [
1580 'LAST_AUTH' => $date,
1581 'IP_ADDR' => $ipExpr,
1586 UserStoredAuthTable::add([
1587 'USER_ID' => $arUser[
"ID"],
1588 'DATE_REG' => $date,
1589 'LAST_AUTH' => $date,
1590 'TEMP_HASH' => ($bSave ?
'N' :
'Y'),
1591 'IP_ADDR' => $ipExpr,
1592 'STORED_HASH' =>
$hash,
1597 if (($applicationPassId =
$context->getApplicationPasswordId()) !==
null)
1602 'LAST_IP' =>
$_SERVER[
"REMOTE_ADDR"],
1606 if (isset(
$_SERVER[
'BX24_REQUEST_ID']))
1611 if (
Option::get(
'main',
'event_log_login_success',
'N') ===
'Y')
1616 if (
Option::get(
'main',
'user_device_history',
'N') ===
'Y')
1623 "user_fields" => $arUser,
1625 "update" => $bUpdate,
1626 "applicationId" =>
$context->getApplicationId(),
1630 foreach (
GetModuleEvents(
'main',
'OnAfterUserAuthorize',
true) as $arEvent)
1646 $this->CheckAuthActions();
1657 ->setPreviousUserId($this->
GetID())
1658 ->setMethod(Method::LoginAs)
1668 $context = Main\Context::getCurrent();
1672 $secure = (
Option::get(
'main',
'use_secure_password_cookies',
'N') ==
'Y' &&
$request->isHttps());
1676 $period = time() + 60 * 60 * 24 * 30 * 12;
1687 $cookie->setSecure($secure)
1688 ->setSpread($spread)
1696 $cookie->setSecure($secure)
1697 ->setSpread($spread)
1716 if (!is_string(
$login) || !is_string(
$password) || !is_string($remember) || !is_string($password_original))
1721 $result_message =
true;
1725 ->setMethod(Method::Password)
1731 "REMEMBER" => &$remember,
1732 "PASSWORD_ORIGINAL" => &$password_original,
1736 unset(static::$kernelSession[
"SESS_OPERATIONS"]);
1741 foreach (
GetModuleEvents(
'main',
'OnBeforeUserLogin',
true) as $arEvent)
1747 $result_message = [
"MESSAGE" => $err->GetString() .
"<br>",
"TYPE" =>
"ERROR"];
1752 $result_message = [
"MESSAGE" =>
"Unknown login error" .
"<br>",
"TYPE" =>
"ERROR"];
1763 foreach (
GetModuleEvents(
'main',
'OnUserLoginExternal',
true) as $arEvent)
1769 $result_message =
$arParams[
"RESULT_MESSAGE"];
1773 $context->setMethod(Method::External);
1786 foreach (
GetModuleEvents(
'main',
'OnFindExternalUser',
true) as $arEvent)
1795 $user_id = $external_user_id;
1796 $result_message =
true;
1799 ->setApplicationId($appPassword[
"APPLICATION_ID"])
1800 ->setApplicationPasswordId($appPassword[
"ID"])
1801 ->setMethod(Method::AppPassword)
1812 if ($user_id > 1 && (!isset(
$arParams[
"CONTROLLER_ADMIN"]) ||
$arParams[
"CONTROLLER_ADMIN"] !==
'Y'))
1814 if (!static::CheckUsersCount($user_id))
1819 "MESSAGE" =>
GetMessage(
"LIMIT_USERS_COUNT") .
"<br>",
1827 $doAuthorize =
true;
1831 if (
$context->getApplicationId() ===
null && CModule::IncludeModule(
"security"))
1859 $result_message =
false;
1866 Main\Context::getCurrent()->getResponse()->addCookie($cookie);
1871 if (CModule::IncludeModule(
"security"))
1878 $arParams[
"RESULT_MESSAGE"] = $result_message;
1882 foreach (
GetModuleEvents(
'main',
'OnAfterUserLogin',
true) as $arEvent)
1887 if ($doAuthorize && $result_message !==
true && (
Option::get(
'main',
'event_log_login_fail',
'N') ===
'Y'))
1889 $auditType =
$error[
'auditType'] ??
'USER_LOGIN';
1891 $info[
'message'] = $result_message[
'MESSAGE'];
1912 $errorType =
"LOGIN";
1915 "SELECT U.ID, U.LOGIN, U.ACTIVE, U.BLOCKED, U.PASSWORD, U.PASSWORD_EXPIRED, U.LOGIN_ATTEMPTS, U.CONFIRM_CODE, U.EMAIL " .
1917 "WHERE U.LOGIN='" .
$DB->ForSQL(
$arParams[
"LOGIN"]) .
"' ";
1919 if (!empty(
$arParams[
"EXTERNAL_AUTH_ID"]))
1922 $strSql .=
" AND EXTERNAL_AUTH_ID='" .
$DB->ForSql(
$arParams[
"EXTERNAL_AUTH_ID"]) .
"'";
1927 $strSql .=
" AND (EXTERNAL_AUTH_ID IS NULL OR EXTERNAL_AUTH_ID='') ";
1932 if (($arUser =
$result->Fetch()))
1934 $passwordCorrect =
false;
1936 $applicationId =
null;
1937 $original = isset(
$arParams[
"PASSWORD_ORIGINAL"]) &&
$arParams[
"PASSWORD_ORIGINAL"] ===
'Y';
1938 $loginAttempts = intval($arUser[
"LOGIN_ATTEMPTS"]) + 1;
1941 'userId' => $arUser[
"ID"],
1942 'active' => $arUser[
"ACTIVE"],
1943 'blocked' => $arUser[
"BLOCKED"],
1944 'loginAttempts' => $loginAttempts,
1947 if ($arUser[
"BLOCKED"] !=
'Y')
1949 $policy = static::getPolicy($arUser[
"ID"]);
1952 $correctCaptcha =
true;
1953 $policyLoginAttempts = (int)$policy->getLoginAttempts();
1954 if ($policyLoginAttempts > 0 && $loginAttempts > $policyLoginAttempts)
1959 $error[
'auditType'] =
'USER_LOGIN_INCORRECT_CAPTCHA';
1960 $error[
'info'][
'policyLoginAttempts'] = $policyLoginAttempts;
1962 $correctCaptcha =
false;
1966 if ($correctCaptcha)
1970 if (!$passwordCorrect)
1975 $passwordWithoutOtp = mb_substr(
$arParams[
"PASSWORD"], 0, -6);
1976 $passwordCorrect =
Password::equals($arUser[
"PASSWORD"], $passwordWithoutOtp);
1985 if (!$passwordCorrect)
1990 $passwordCorrect =
true;
1991 $applicationId = $appPassword[
"APPLICATION_ID"];
1996 ->setApplicationId($applicationId)
1997 ->setApplicationPasswordId($appPassword[
"ID"])
1998 ->setMethod(Method::AppPassword)
2005 if (!$passwordCorrect)
2008 $policyBlockAttempts = (int)$policy->getBlockLoginAttempts();
2009 $policyBlockTime = (int)$policy->getBlockTime();
2010 if ($policyBlockAttempts > 0 && $policyBlockTime > 0 && $loginAttempts >= $policyBlockAttempts)
2012 if ($arUser[
"ACTIVE"] ==
'Y')
2014 static::blockUser($arUser[
"ID"], $policyBlockTime, $loginAttempts);
2021 $error[
'auditType'] =
'USER_LOGIN_BLOCKED';
2024 if ($passwordCorrect)
2027 if ($applicationId ===
null)
2036 $DB->Query(
"UPDATE b_user SET PASSWORD='" .
$DB->ForSQL($newPassword) .
"', TIMESTAMP_X = TIMESTAMP_X WHERE ID = " . intval($arUser[
"ID"]));
2040 if (
Option::get(
'main',
'use_digest_auth',
'N') ==
'Y')
2042 static::UpdateDigest($arUser[
"ID"],
$arParams[
"PASSWORD"]);
2046 $passwordExpired =
false;
2047 if ($arUser[
'PASSWORD_EXPIRED'] ==
'Y')
2050 $passwordExpired =
true;
2051 $error[
'info'][
'passwordExpired'] =
'Y';
2053 if (!$passwordExpired && $original && $policy->getPasswordCheckPolicy())
2055 $passwordErrors = static::CheckPasswordAgainstPolicy(
$arParams[
"PASSWORD"], $policy->getValues());
2056 if (!empty($passwordErrors))
2059 $passwordExpired =
true;
2060 $error[
'info'][
'passwordExpired'] =
'Policy';
2063 if (!$passwordExpired)
2065 $policyChangeDays = (int)$policy->getPasswordChangeDays();
2066 if ($policyChangeDays > 0)
2069 if (UserPasswordTable::passwordExpired($arUser[
"ID"], $policyChangeDays))
2071 $passwordExpired =
true;
2072 $error[
'info'][
'passwordExpired'] =
'Days';
2073 $error[
'info'][
'passwordExpiredDays'] = $policyChangeDays;
2078 if ($passwordExpired)
2080 $passwordCorrect =
false;
2082 $errorType =
"CHANGE_PASSWORD";
2086 if ($passwordCorrect)
2088 if ($arUser[
"ACTIVE"] ==
'Y')
2091 $user_id = $arUser[
"ID"];
2096 if ($arUser[
"CONFIRM_CODE"] !=
'')
2107 if (
Option::get(
'main',
'new_user_phone_auth',
'N') ==
'Y')
2110 if ($row && $row[
"CONFIRMED"] ==
'N')
2112 $message =
GetMessage(
"main_login_need_phone_confirmation", [
"#PHONE#" => $row[
"PHONE_NUMBER"]]);
2122 $DB->Query(
"UPDATE b_user SET LOGIN_ATTEMPTS = " . $loginAttempts .
", TIMESTAMP_X = TIMESTAMP_X WHERE ID = " . intval($arUser[
"ID"]));
2127 $error[
'auditType'] =
'USER_LOGIN_NOT_FOUND';
2136 "ERROR_TYPE" => $errorType,
2137 "IS_CAPTCHA_ERROR" => !($correctCaptcha ??
true),
2150 $unblockDate->add(
"T{$blockTime}M");
2152 CAgent::AddAgent(
"CUser::UnblockAgent({$userId});",
'main',
'Y', 0,
'',
'Y', $unblockDate->toString());
2154 if (
Option::get(
'main',
'event_log_block_user',
'N') ===
'Y')
2160 private static function CheckUsersCount($user_id)
2162 $user_id = (int)$user_id;
2164 $limitUsersCount =
$license->getMaxUsers();
2166 if ($limitUsersCount > 0)
2172 if (
$count >= $limitUsersCount)
2187 $query = static::GetList(
'id',
'asc',
2188 [
'ID_EQUAL_EXACT' => $user_id],
2194 if ($currentUser =
$query->Fetch())
2196 if ($currentUser[
"LAST_LOGIN"] !=
'')
2198 $loginDate =
new DateTime($currentUser[
"LAST_LOGIN"]);
2199 if ($loginDate->getTimestamp() > $today->getTimestamp())
2206 if ($intranet && empty($currentUser[
"UF_DEPARTMENT"]))
2209 if (
$license->isExtraCountable() && Main\Loader::includeModule(
'extranet'))
2211 $extranetServiceContainer = Extranet\Service\ServiceContainer::getInstance();
2213 if ($extranetServiceContainer->getCollaberService()->isCollaberById($user_id))
2218 $groupId = (int)Option::get(
'extranet',
'extranet_group');
2220 if ($groupId > 0 && in_array($groupId, static::GetUserGroup($user_id)))
2234 public function LoginByOtp(
$otp, $remember_otp =
'N', $captcha_word =
'', $captcha_sid =
'')
2236 if (!CModule::IncludeModule(
"security") || !\
Bitrix\
Security\
Mfa\Otp::isOtpRequired())
2238 return [
"MESSAGE" =>
GetMessage(
"USER_LOGIN_OTP_ERROR") .
"<br>",
"TYPE" =>
"ERROR"];
2243 $userParams[
"OTP"] =
$otp;
2244 $userParams[
"OTP_REMEMBER"] = ($remember_otp ===
'Y');
2245 $userParams[
"CAPTCHA_WORD"] = $captcha_word;
2246 $userParams[
"CAPTCHA_SID"] = $captcha_sid;
2250 return [
"MESSAGE" =>
GetMessage(
"USER_LOGIN_OTP_INCORRECT") .
"<br>",
"TYPE" =>
"ERROR"];
2254 ->setUserId($userParams[
"USER_ID"])
2255 ->setMethod(Method::Otp)
2264 $doAuthorize =
true;
2266 if (CModule::IncludeModule(
"security"))
2279 return $this->
Authorize($user_id, $bSave);
2285 public function ChangePassword($LOGIN, $CHECKWORD, $PASSWORD, $CONFIRM_PASSWORD,
$SITE_ID =
false, $captcha_word =
'', $captcha_sid = 0, $authActions =
true, $phoneNumber =
'', $currentPassword =
'')
2290 if (!is_string($LOGIN) || !is_string($CHECKWORD) || !is_string($PASSWORD) || !is_string($CONFIRM_PASSWORD) || !is_string($phoneNumber) || !is_string($currentPassword))
2292 return [
"MESSAGE" =>
GetMessage(
"main_change_pass_error") .
"<br>",
"TYPE" =>
"ERROR"];
2297 "CHECKWORD" => &$CHECKWORD,
2298 "PASSWORD" => &$PASSWORD,
2299 "CONFIRM_PASSWORD" => &$CONFIRM_PASSWORD,
2301 "PHONE_NUMBER" => &$phoneNumber,
2302 "CURRENT_PASSWORD" => &$currentPassword,
2306 foreach (
GetModuleEvents(
'main',
'OnBeforeUserChangePassword',
true) as $arEvent)
2312 return [
"MESSAGE" => $err->GetString() .
"<br>",
"TYPE" =>
"ERROR"];
2314 return [
"MESSAGE" =>
GetMessage(
"main_change_pass_error") .
"<br>",
"TYPE" =>
"ERROR"];
2318 if (
Option::get(
'main',
'captcha_restoring_password',
'N') ==
'Y')
2320 if (!(
$APPLICATION->CaptchaCheckCode($captcha_word, $captcha_sid)))
2322 return [
"MESSAGE" =>
GetMessage(
"main_user_captcha_error") .
"<br>",
"TYPE" =>
"ERROR"];
2326 $phoneAuth = (
$arParams[
"PHONE_NUMBER"] !=
'' &&
Option::get(
'main',
'new_user_phone_auth',
'N') ==
'Y');
2329 if (mb_strlen(
$arParams[
"LOGIN"]) < 3 && !$phoneAuth)
2331 $strAuthError .=
GetMessage(
'MIN_LOGIN') .
"<br>";
2335 $strAuthError .=
GetMessage(
"main_change_pass_empty_checkword") .
"<br>";
2339 $strAuthError .=
GetMessage(
'WRONG_CONFIRMATION') .
"<br>";
2341 if ($strAuthError !=
'')
2343 return [
"MESSAGE" => $strAuthError,
"TYPE" =>
"ERROR"];
2357 return [
"MESSAGE" =>
GetMessage(
"main_change_pass_code_error"),
"TYPE" =>
"ERROR"];
2361 $updateFields[
"ACTIVE"] =
'Y';
2365 CTimeZone::Disable();
2366 $db_check =
$DB->Query(
2367 "SELECT ID, LID, CHECKWORD, " .
$DB->DateToCharFunction(
"CHECKWORD_TIME") .
" as CHECKWORD_TIME, PASSWORD, LOGIN_ATTEMPTS, ACTIVE, BLOCKED " .
2369 "WHERE LOGIN='" .
$DB->ForSql(
$arParams[
"LOGIN"]) .
"'" .
2373 ?
" AND EXTERNAL_AUTH_ID='" .
$DB->ForSQL(
$arParams[
"EXTERNAL_AUTH_ID"]) .
"' "
2374 :
" AND (EXTERNAL_AUTH_ID IS NULL OR EXTERNAL_AUTH_ID='') "
2377 CTimeZone::Enable();
2379 if (!(
$res = $db_check->Fetch()))
2383 return [
"MESSAGE" =>
GetMessage(
"CHECKWORD_INCORRECT1") .
"<br>",
"TYPE" =>
"ERROR",
"FIELD" =>
"CHECKWORD"];
2385 return [
"MESSAGE" =>
GetMessage(
"main_change_pass_incorrect_pass") .
"<br>",
"TYPE" =>
"ERROR",
"FIELD" =>
"CURRENT_PASSWORD"];
2391 $policy = static::getPolicy(
$userId);
2400 return [
"MESSAGE" =>
GetMessage(
"CHECKWORD_INCORRECT1") .
"<br>",
"TYPE" =>
"ERROR",
"FIELD" =>
"CHECKWORD"];
2403 $site_format = CSite::GetDateFormat();
2404 if (time() - $policy->getCheckwordTimeout() * 60 >
MakeTimeStamp(
$res[
"CHECKWORD_TIME"], $site_format))
2406 return [
"MESSAGE" =>
GetMessage(
"CHECKWORD_EXPIRE") .
"<br>",
"TYPE" =>
"ERROR",
"FIELD" =>
"CHECKWORD_EXPIRE"];
2412 $loginAttempts = intval(
$res[
"LOGIN_ATTEMPTS"]) + 1;
2415 $policyLoginAttempts = (int)$policy->getLoginAttempts();
2416 if ($policyLoginAttempts > 0 && $loginAttempts > $policyLoginAttempts)
2419 if (!
$APPLICATION->CaptchaCheckCode($captcha_word, $captcha_sid))
2421 return [
"MESSAGE" =>
GetMessage(
"main_user_captcha_error") .
"<br>",
"TYPE" =>
"ERROR"];
2425 $passwordCorrect =
false;
2427 if (
$res[
"BLOCKED"] !=
'Y')
2431 if (!$passwordCorrect)
2434 $policyBlockAttempts = (int)$policy->getBlockLoginAttempts();
2435 $policyBlockTime = (int)$policy->getBlockTime();
2436 if ($policyBlockAttempts > 0 && $policyBlockTime > 0 && $loginAttempts >= $policyBlockAttempts)
2438 if (
$res[
"ACTIVE"] ==
'Y')
2440 static::blockUser(
$res[
"ID"], $policyBlockTime, $loginAttempts);
2450 if (!$passwordCorrect)
2453 $DB->Query(
"UPDATE b_user SET LOGIN_ATTEMPTS = " . $loginAttempts .
", TIMESTAMP_X = TIMESTAMP_X WHERE ID = " . intval(
$res[
"ID"]));
2455 return [
"MESSAGE" =>
GetMessage(
"main_change_pass_incorrect_pass") .
"<br>",
"TYPE" =>
"ERROR",
"FIELD" =>
"CURRENT_PASSWORD"];
2472 $passwordErrors = static::CheckPasswordAgainstPolicy(
$arParams[
"PASSWORD"], $policy->getValues(),
$userId);
2473 if (!empty($passwordErrors))
2475 return [
"MESSAGE" => implode(
"<br>", $passwordErrors) .
"<br>",
"TYPE" =>
"ERROR"];
2479 $obUser =
new CUser;
2480 $res = $obUser->Update(
$userId, $updateFields, $authActions);
2482 if (!
$res && $obUser->LAST_ERROR !=
'')
2484 return [
"MESSAGE" => $obUser->LAST_ERROR .
"<br>",
"TYPE" =>
"ERROR"];
2489 return [
"MESSAGE" =>
GetMessage(
"main_change_pass_changed") .
"<br>",
"TYPE" =>
"OK"];
2495 return [
"MESSAGE" =>
GetMessage(
'PASSWORD_CHANGE_OK') .
"<br>",
"TYPE" =>
"OK"];
2501 $policy = static::getPolicy(
$groups);
2504 if ($policy->getPasswordPunctuation())
2509 $length = (int)$policy->getPasswordLength();
2518 $passwordMinLength = intval(
$arPolicy[
'PASSWORD_LENGTH']);
2519 if ($passwordMinLength <= 0)
2521 $passwordMinLength = 6;
2523 if (mb_strlen(
$password) < $passwordMinLength)
2543 if ((
$arPolicy[
'PASSWORD_PUNCTUATION'] ===
'Y') && !preg_match(
'/[' . preg_quote(static::PASSWORD_SPECIAL_CHARS,
'/') .
']/',
$password))
2545 $errors[] =
GetMessage(
'MAIN_FUNCTION_REGISTER_PASSWORD_PUNCTUATION', [
'#SPECIAL_CHARS#' => static::PASSWORD_SPECIAL_CHARS]);
2548 if ((
$arPolicy[
'PASSWORD_CHECK_WEAK'] ===
'Y'))
2550 if (
Option::get(
'main',
'custom_weak_passwords') ===
'Y')
2552 $uploadDir =
Option::get(
'main',
'upload_dir',
'upload');
2553 $path =
"{$_SERVER['DOCUMENT_ROOT']}/{$uploadDir}/main/weak_passwords";
2557 $path =
"{$_SERVER['DOCUMENT_ROOT']}/bitrix/modules/main/data/weak_passwords";
2567 if (
$arPolicy[
'PASSWORD_UNIQUE_COUNT'] > 0 ||
$arPolicy[
'PASSWORD_MIN_CHANGE_DAYS'] > 0)
2569 $limit =
$arPolicy[
'PASSWORD_UNIQUE_COUNT'] > 0 ?
$arPolicy[
'PASSWORD_UNIQUE_COUNT'] : 1;
2570 $passwords = UserPasswordTable::getUserPasswords(
$userId, $limit);
2572 if (
$arPolicy[
'PASSWORD_UNIQUE_COUNT'] > 0)
2574 foreach ($passwords as $previousPassword)
2584 if (
$arPolicy[
'PASSWORD_MIN_CHANGE_DAYS'] > 0)
2586 foreach ($passwords as $previousPassword)
2588 if ((time() - $previousPassword[
'DATE_CHANGE']->getTimestamp())/86400 <
$arPolicy[
'PASSWORD_MIN_CHANGE_DAYS'])
2613 foreach (
GetModuleEvents(
'main',
'OnBeforeSendUserInfo',
true) as $arEvent)
2628 $strSql =
"UPDATE b_user SET " .
2630 " CHECKWORD_TIME = " .
$DB->CurrentTimeFunction() .
", " .
2632 " TIMESTAMP_X = TIMESTAMP_X " .
2633 "WHERE ID = '" .
$ID .
"'" .
2637 ?
" AND EXTERNAL_AUTH_ID='" .
$DB->ForSQL(
$arParams[
"EXTERNAL_AUTH_ID"]) .
"' "
2638 :
" AND (EXTERNAL_AUTH_ID IS NULL OR EXTERNAL_AUTH_ID='') "
2641 $DB->Query($strSql);
2647 "WHERE ID='" .
$ID .
"'" .
2650 ?
" AND EXTERNAL_AUTH_ID='" .
$DB->ForSQL(
$arParams[
"EXTERNAL_AUTH_ID"]) .
"' "
2651 :
" AND (EXTERNAL_AUTH_ID IS NULL OR EXTERNAL_AUTH_ID='') "
2655 if ($res_array =
$res->Fetch())
2659 "USER_ID" => $res_array[
"ID"],
2660 "STATUS" => ($res_array[
"ACTIVE"] ==
'Y' ?
GetMessage(
"STATUS_ACTIVE") :
GetMessage(
"STATUS_BLOCKED")),
2662 "LOGIN" => $res_array[
"LOGIN"],
2663 "URL_LOGIN" => urlencode($res_array[
"LOGIN"]),
2665 "NAME" => $res_array[
"NAME"],
2666 "LAST_NAME" => $res_array[
"LAST_NAME"],
2667 "EMAIL" => $res_array[
"EMAIL"],
2672 "USER_FIELDS" => $res_array,
2674 "EVENT_NAME" => &$eventName,
2693 public static function SendPassword($LOGIN, $EMAIL,
$SITE_ID =
false, $captcha_word =
'', $captcha_sid = 0, $phoneNumber =
'', $shortCode =
false)
2702 "PHONE_NUMBER" => $phoneNumber,
2703 "SHORT_CODE" => $shortCode,
2706 $result_message = [
"MESSAGE" =>
GetMessage(
'ACCOUNT_INFO_SENT') .
"<br>",
"TYPE" =>
"OK"];
2709 foreach (
GetModuleEvents(
'main',
'OnBeforeUserSendPassword',
true) as $arEvent)
2715 $result_message = [
"MESSAGE" => $err->GetString() .
"<br>",
"TYPE" =>
"ERROR"];
2723 if ($bOk && !
$arParams[
"SHORT_CODE"] &&
Option::get(
'main',
'captcha_restoring_password',
'N') ==
'Y')
2725 if (!(
$APPLICATION->CaptchaCheckCode($captcha_word, $captcha_sid)))
2727 $result_message = [
"MESSAGE" =>
GetMessage(
"main_user_captcha_error") .
"<br>",
"TYPE" =>
"ERROR"];
2743 $result_message = [
"MESSAGE" =>
GetMessage(
"main_user_pass_request_sent") .
"<br>",
"TYPE" =>
"OK",
"TEMPLATE" =>
"SMS_USER_RESTORE_PASSWORD"];
2749 if (
Option::get(
'main',
'event_log_password_request',
'N') ===
'Y')
2757 if (
$result->getErrorCollection()->getErrorByCode(
"ERR_NOT_FOUND") ===
null)
2761 $result_message = [
"MESSAGE" => implode(
"<br>",
$result->getErrorMessages()),
"TYPE" =>
"ERROR"];
2767 $confirmation = (
Option::get(
'main',
'new_user_registration_email_confirmation',
'N') ==
'Y');
2773 "SELECT ID, LID, ACTIVE, BLOCKED, CONFIRM_CODE, LOGIN, EMAIL, NAME, LAST_NAME, LANGUAGE_ID " .
2775 "WHERE LOGIN='" .
$DB->ForSQL(
$arParams[
"LOGIN"]) .
"' " .
2776 " AND (ACTIVE='Y' OR NOT(CONFIRM_CODE IS NULL OR CONFIRM_CODE='')) " .
2780 ?
" AND EXTERNAL_AUTH_ID='" .
$DB->ForSQL(
$arParams[
"EXTERNAL_AUTH_ID"]) .
"' "
2781 :
" AND (EXTERNAL_AUTH_ID IS NULL OR EXTERNAL_AUTH_ID='') "
2788 $strSql .=
"\nUNION\n";
2791 "SELECT ID, LID, ACTIVE, BLOCKED, CONFIRM_CODE, LOGIN, EMAIL, NAME, LAST_NAME, LANGUAGE_ID " .
2793 "WHERE EMAIL='" .
$DB->ForSQL(
$arParams[
"EMAIL"]) .
"' " .
2794 " AND (ACTIVE='Y' OR NOT(CONFIRM_CODE IS NULL OR CONFIRM_CODE='')) " .
2797 ?
" AND EXTERNAL_AUTH_ID='" .
$DB->ForSQL(
$arParams[
"EXTERNAL_AUTH_ID"]) .
"' "
2798 :
" AND (EXTERNAL_AUTH_ID IS NULL OR EXTERNAL_AUTH_ID='') "
2803 while ($arUser =
$res->Fetch())
2809 $arParams[
"SITE_ID"] = CSite::GetDefSite($arUser[
"LID"]);
2817 if ($arUser[
"ACTIVE"] ==
'Y')
2819 if ($arUser[
"BLOCKED"] !=
'Y')
2829 $result_message = [
"MESSAGE" =>
GetMessage(
"main_send_password_email_code") .
"<br>",
"TYPE" =>
"OK",
"USER_ID" => $arUser[
"ID"],
"RESULT" =>
$result];
2833 $result_message = [
"MESSAGE" => implode(
"<br>",
$result->getErrorMessages()),
"TYPE" =>
"ERROR",
"RESULT" =>
$result];
2838 static::SendUserInfo($arUser[
"ID"],
$arParams[
"SITE_ID"],
GetMessage(
"INFO_REQ"),
true,
'USER_PASS_REQUEST');
2848 "USER_ID" => $arUser[
"ID"],
2849 "LOGIN" => $arUser[
"LOGIN"],
2850 "EMAIL" => $arUser[
"EMAIL"],
2851 "NAME" => $arUser[
"NAME"],
2852 "LAST_NAME" => $arUser[
"LAST_NAME"],
2853 "CONFIRM_CODE" => $arUser[
"CONFIRM_CODE"],
2854 "USER_IP" =>
$_SERVER[
"REMOTE_ADDR"],
2855 "USER_HOST" => @gethostbyaddr(
$_SERVER[
"REMOTE_ADDR"]),
2861 $result_message = [
"MESSAGE" =>
GetMessage(
"MAIN_SEND_PASS_CONFIRM") .
"<br>",
"TYPE" =>
"OK"];
2864 if (
Option::get(
'main',
'event_log_password_request',
'N') ===
'Y')
2872 if (
Option::get(
'main',
'event_log_password_request',
'N') ===
'Y')
2879 return $result_message;
2882 public function Register($USER_LOGIN, $USER_NAME, $USER_LAST_NAME, $USER_PASSWORD, $USER_CONFIRM_PASSWORD, $USER_EMAIL,
$SITE_ID =
false, $captcha_word =
'', $captcha_sid = 0, $bSkipConfirm =
false, $USER_PHONE_NUMBER =
'')
2894 return [
"MESSAGE" =>
GetMessage(
"MAIN_FUNCTION_REGISTER_NA_INADMIN"),
"TYPE" =>
"ERROR"];
2899 if (
Option::get(
'main',
'captcha_registration',
'N') ==
'Y')
2901 if (!(
$APPLICATION->CaptchaCheckCode($captcha_word, $captcha_sid)))
2909 if (
Option::get(
'main',
'event_log_register_fail',
'N') ===
'Y')
2915 return [
"MESSAGE" =>
$strError,
"TYPE" =>
"ERROR"];
2923 $bConfirmReq = !$bSkipConfirm && (
Option::get(
'main',
'new_user_registration_email_confirmation',
'N') ==
'Y' &&
Option::get(
'main',
'new_user_email_required',
'Y') !=
'N');
2924 $phoneRegistration = (
Option::get(
'main',
'new_user_phone_auth',
'N') ==
'Y');
2925 $phoneRequired = ($phoneRegistration &&
Option::get(
'main',
'new_user_phone_required',
'N') ==
'Y');
2927 $active = ($bConfirmReq || $phoneRequired ?
'N' :
'Y');
2930 "LOGIN" => $USER_LOGIN,
2931 "NAME" => $USER_NAME,
2932 "LAST_NAME" => $USER_LAST_NAME,
2933 "PASSWORD" => $USER_PASSWORD,
2935 "~CHECKWORD_TIME" =>
$DB->CurrentTimeFunction(),
2936 "CONFIRM_PASSWORD" => $USER_CONFIRM_PASSWORD,
2937 "EMAIL" => $USER_EMAIL,
2938 "PHONE_NUMBER" => $USER_PHONE_NUMBER,
2939 "ACTIVE" => $active,
2942 "LANGUAGE_ID" => LANGUAGE_ID,
2943 "USER_IP" =>
$_SERVER[
"REMOTE_ADDR"],
2944 "USER_HOST" => @gethostbyaddr(
$_SERVER[
"REMOTE_ADDR"]),
2948 $def_group =
Option::get(
'main',
'new_user_registration_def_group');
2949 if ($def_group !=
'')
2951 $arFields[
"GROUP_ID"] = explode(
",", $def_group);
2955 $result_message =
true;
2956 foreach (
GetModuleEvents(
'main',
'OnBeforeUserRegister',
true) as $arEvent)
2962 $result_message = [
"MESSAGE" => $err->GetString() .
"<br>",
"TYPE" =>
"ERROR"];
2967 $result_message = [
"MESSAGE" =>
"Unknown error" .
"<br>",
"TYPE" =>
"ERROR"];
2981 $arFields[
"SITE_ID"] = CSite::GetDefSite();
2987 if ($phoneRegistration &&
$arFields[
"PHONE_NUMBER"] !=
'')
2992 [
$code, $phoneNumber] = static::GeneratePhoneCode(
$ID);
2995 "SMS_USER_CONFIRM_NUMBER",
2997 "USER_PHONE" => $phoneNumber,
3002 $smsResult = $sms->send(
true);
3006 if ($smsResult->isSuccess())
3009 "MESSAGE" =>
GetMessage(
"main_register_sms_sent"),
3011 "SIGNED_DATA" => $signedData,
3018 "MESSAGE" => implode(
' ', $smsResult->getErrorMessages()),
3020 "SIGNED_DATA" => $signedData,
3037 unset($arEventFields[
"PASSWORD"]);
3038 unset($arEventFields[
"CONFIRM_PASSWORD"]);
3039 unset($arEventFields[
"~CHECKWORD_TIME"]);
3042 $event->SendImmediate(
"NEW_USER", $arEventFields[
"SITE_ID"], $arEventFields);
3045 $event->SendImmediate(
"NEW_USER_CONFIRM", $arEventFields[
"SITE_ID"], $arEventFields);
3055 if (is_array($result_message))
3057 if ($result_message[
"TYPE"] ==
"OK")
3059 if (
Option::get(
'main',
'event_log_register',
'N') ===
'Y')
3066 if (
Option::get(
'main',
'event_log_register_fail',
'N') ===
'Y')
3074 $isAuthorize =
false;
3075 if (
$ID !==
false &&
$arFields[
"ACTIVE"] ===
'Y' && $phoneReg ===
false)
3079 ->setMethod(Method::Registration)
3084 $agreementId = (int)
Option::get(
'main',
'new_user_agreement');
3085 if ($agreementId && $isAuthorize)
3088 if ($agreementObject->isExist() && $agreementObject->isActive() &&
$_REQUEST[
"USER_AGREEMENT"] ==
'Y')
3094 $arFields[
"RESULT_MESSAGE"] = $result_message;
3095 foreach (
GetModuleEvents(
'main',
'OnAfterUserRegister',
true) as $arEvent)
3112 return [
"MESSAGE" =>
GetMessage(
"MAIN_FUNCTION_SIMPLEREGISTER_NA_INADMIN"),
"TYPE" =>
"ERROR"];
3120 global $REMOTE_ADDR;
3124 "~CHECKWORD_TIME" =>
$DB->CurrentTimeFunction(),
3125 "EMAIL" => $USER_EMAIL,
3129 "USER_IP" => $REMOTE_ADDR,
3130 "USER_HOST" => @gethostbyaddr($REMOTE_ADDR),
3132 "LANGUAGE_ID" => LANGUAGE_ID,
3135 $def_group =
Option::get(
'main',
'new_user_registration_def_group');
3136 if ($def_group !=
'')
3138 $arFields[
"GROUP_ID"] = explode(
",", $def_group);
3147 $result_message =
false;
3148 foreach (
GetModuleEvents(
'main',
'OnBeforeUserSimpleRegister',
true) as $arEvent)
3154 $result_message = [
"MESSAGE" => $err->GetString() .
"<br>",
"TYPE" =>
"ERROR"];
3159 $result_message = [
"MESSAGE" =>
"Unknown error" .
"<br>",
"TYPE" =>
"ERROR"];
3167 $bRandLogin =
false;
3189 ->setMethod(Method::Registration)
3197 unset($arEventFields[
"PASSWORD"]);
3198 unset($arEventFields[
"CONFIRM_PASSWORD"]);
3200 $event->SendImmediate(
"NEW_USER", $arEventFields[
"SITE_ID"], $arEventFields);
3201 static::SendUserInfo(
$ID, $arEventFields[
"SITE_ID"],
GetMessage(
"USER_REGISTERED_SIMPLE"),
true);
3202 $result_message = [
"MESSAGE" =>
GetMessage(
"USER_REGISTER_OK"),
"TYPE" =>
"OK"];
3210 if (is_array($result_message))
3212 if ($result_message[
"TYPE"] ==
"OK")
3214 if (
Option::get(
'main',
'event_log_register',
'N') ===
'Y')
3221 if (
Option::get(
'main',
'event_log_register_fail',
'N') ===
'Y')
3228 $arFields[
"RESULT_MESSAGE"] = $result_message;
3229 foreach (
GetModuleEvents(
'main',
'OnAfterUserSimpleRegister',
true) as $arEvent)
3241 trigger_error(
"Static call CUser::IsAuthorized() is deprecated, will be removed soon. Use global \$USER.", E_USER_WARNING);
3244 return $USER->IsAuthorized();
3246 return ($this->
GetID() > 0);
3256 $filePath = Main\Context::getCurrent()->getRequest()->getScriptFile();
3268 if (!$this->
GetParam(
'PREV_LAST_ACTIVITY'))
3280 if ($this->admin ===
null)
3283 Option::get(
'main',
'controller_member',
'N') ==
'Y'
3284 &&
Option::get(
'main',
'~controller_limited_admin',
'N') ==
'Y'
3287 $this->admin = ($this->
GetParam(
"CONTROLLER_ADMIN") ===
true);
3291 $this->admin = ($this->
GetParam(
"ADMIN") ===
true);
3299 $this->
SetParam(
"CONTROLLER_ADMIN", (
bool)$isAdmin);
3308 $logout =
'logout=yes';
3310 if (
Option::get(
'main',
'secure_logout',
'N') ==
'Y')
3315 if ($deleteParms !==
true)
3317 if (($s =
DeleteParam(array_merge($deleteParms, [
"logout",
"sessid"]))) !=
'')
3319 $logout .=
'&' . $s;
3331 $USER_ID = $this->
GetID();
3334 "USER_ID" => &$USER_ID,
3339 foreach (
GetModuleEvents(
'main',
'OnBeforeUserLogout',
true) as $arEvent)
3360 if (($storedAuthId = $this->
getContext()->getStoredAuthId()) > 0)
3362 UserStoredAuthTable::delete($storedAuthId);
3365 $this->justAuthorized =
false;
3366 $this->admin =
null;
3367 $this->context =
null;
3369 static::$kernelSession[
"SESS_AUTH"] = [];
3370 unset(static::$kernelSession[
"SESS_AUTH"]);
3371 unset(static::$kernelSession[
"SESS_OPERATIONS"]);
3372 unset(static::$kernelSession[
'fixed_session_id']);
3377 $compositeSessionManager =
$application->getCompositeSessionManager();
3379 $compositeSessionManager->regenerateId();
3381 $response = Main\Context::getCurrent()->getResponse();
3385 $cookie->setSpread($spread);
3386 $cookie->setHttpOnly(
true);
3390 $cookie->setSpread($spread);
3391 $cookie->setHttpOnly(
true);
3398 foreach (
GetModuleEvents(
'main',
'OnAfterUserLogout',
true) as $arEvent)
3403 if (
Option::get(
'main',
'event_log_logout',
'N') ===
'Y')
3412 if (!isset(self::$userGroupCache[
$ID]))
3415 $res = static::GetUserGroupEx(
$ID);
3416 while ($r =
$res->Fetch())
3418 $arr[] = $r[
"GROUP_ID"];
3421 self::$userGroupCache[
$ID] =
$arr;
3424 return self::$userGroupCache[
$ID];
3432 SELECT UG.GROUP_ID, G.STRING_ID,
3433 " .
$DB->DateToCharFunction(
"UG.DATE_ACTIVE_FROM") .
" as DATE_ACTIVE_FROM,
3434 " .
$DB->DateToCharFunction(
"UG.DATE_ACTIVE_TO") .
" as DATE_ACTIVE_TO
3435 FROM b_user_group UG INNER JOIN b_group G ON G.ID=UG.GROUP_ID
3436 WHERE UG.USER_ID = " . intval(
$ID) .
"
3437 and ((UG.DATE_ACTIVE_FROM IS NULL) OR (UG.DATE_ACTIVE_FROM <= " .
$DB->CurrentTimeFunction() .
"))
3438 and ((UG.DATE_ACTIVE_TO IS NULL) OR (UG.DATE_ACTIVE_TO >= " .
$DB->CurrentTimeFunction() .
"))
3440 UNION SELECT 2, 'everyone', NULL, NULL ";
3454 " .
$DB->DateToCharFunction(
"UG.DATE_ACTIVE_FROM") .
" as DATE_ACTIVE_FROM,
3455 " .
$DB->DateToCharFunction(
"UG.DATE_ACTIVE_TO") .
" as DATE_ACTIVE_TO
3459 UG.USER_ID = " . intval(
$ID) .
"
3460 UNION SELECT 2, NULL, NULL ";
3475 $this->LAST_ERROR =
'';
3480 if (trim(
$arFields[
"EXTERNAL_AUTH_ID"]) !=
'')
3489 $dbr =
$DB->Query(
"SELECT EXTERNAL_AUTH_ID FROM b_user WHERE ID=" . intval(
$ID));
3490 if ((
$ar = $dbr->Fetch()))
3492 if (
$ar[
'EXTERNAL_AUTH_ID'] !=
'')
3502 $this->LAST_ERROR .= static::CheckInternalFields(
$arFields,
$ID);
3510 $this->LAST_ERROR .=
GetMessage(
"WRONG_EMAIL") .
"<br>";
3517 && (!isset(
$arFields[
"PERSONAL_PHOTO"][
"name"]) ||
$arFields[
"PERSONAL_PHOTO"][
"name"] ==
'')
3518 && (!isset(
$arFields[
"PERSONAL_PHOTO"][
"del"]) ||
$arFields[
"PERSONAL_PHOTO"][
"del"] ==
'')
3524 $maxWidth = (int)
Option::get(
'main',
'profile_image_width', 0);
3525 $maxHeight = (int)
Option::get(
'main',
'profile_image_height', 0);
3526 $maxSize = (int)
Option::get(
'main',
'profile_image_size', 0);
3530 $res = CFile::CheckImageFile(
$arFields[
"PERSONAL_PHOTO"], $maxSize, $maxWidth, $maxHeight);
3533 $this->LAST_ERROR .=
$res .
"<br>";
3539 $this->LAST_ERROR .=
GetMessage(
"WRONG_PERSONAL_BIRTHDAY") .
"<br>";
3553 $res = CFile::CheckImageFile(
$arFields[
"WORK_LOGO"], $maxSize, $maxWidth, $maxHeight);
3556 $this->LAST_ERROR .=
$res .
"<br>";
3563 "SELECT 'x' FROM b_user "
3564 .
"WHERE LOGIN = '{$DB->ForSql($arFields["LOGIN
"], 50)}' "
3565 . (
$ID ===
false ?
'' :
' AND ID <> ' . (
int)
$ID)
3568 ?
" AND EXTERNAL_AUTH_ID = '{$DB->ForSql($arFields["EXTERNAL_AUTH_ID
"])}' "
3569 :
" AND (EXTERNAL_AUTH_ID IS NULL OR {$DB->Length("EXTERNAL_AUTH_ID
")} <= 0)"
3593 foreach ($events as $arEvent)
3596 if ($bEventRes ===
false)
3600 $this->LAST_ERROR .= $err->GetString() .
' ';
3605 $this->LAST_ERROR .=
"Unknown error. ";
3621 $this->LAST_ERROR .= $e->GetString();
3626 $this->LAST_ERROR .=
"Unknown error. ";
3630 if ($this->LAST_ERROR !=
'')
3649 $emailRequired = (
Option::get(
'main',
'new_user_email_required',
'Y') !=
'N');
3650 $phoneRequired = (
Option::get(
'main',
'new_user_phone_required',
'N') ==
'Y');
3656 $resultError .=
GetMessage(
"user_login_not_set") .
"<br>";
3661 $resultError .=
GetMessage(
"user_pass_not_set") .
"<br>";
3664 if ($emailRequired && !isset(
$arFields[
"EMAIL"]))
3666 $resultError .=
GetMessage(
"user_email_not_set") .
"<br>";
3669 if ($phoneRequired && !isset(
$arFields[
"PHONE_NUMBER"]))
3671 $resultError .=
GetMessage(
"main_user_check_no_phone") .
"<br>";
3676 $resultError .=
GetMessage(
"LOGIN_WHITESPACE") .
"<br>";
3681 $resultError .=
GetMessage(
"MIN_LOGIN") .
"<br>";
3689 $resultError .=
GetMessage(
"WRONG_CONFIRMATION") .
"<br>";
3693 if (array_key_exists(
"GROUP_ID",
$arFields))
3698 foreach (
$arFields[
"GROUP_ID"] as $arGroup)
3700 if (is_array($arGroup))
3714 $policy = static::getPolicy(
$ID);
3718 $policy = static::getPolicy([]);
3721 $passwordErrors = static::CheckPasswordAgainstPolicy(
$arFields[
"PASSWORD"], $policy->getValues(), (
$ID !==
false ?
$ID :
null));
3722 if (!empty($passwordErrors))
3724 $resultError .= implode(
"<br>", $passwordErrors) .
"<br>";
3733 $resultError .=
GetMessage(
"WRONG_EMAIL") .
"<br>";
3744 $dbr =
$DB->Query(
"SELECT EMAIL FROM b_user WHERE ID=" . intval(
$ID));
3745 if ((
$ar = $dbr->Fetch()))
3747 $oldEmail =
$ar[
'EMAIL'];
3752 $res = static::GetList(
'',
'',
3755 "EXTERNAL_AUTH_ID" =>
$arFields[
"EXTERNAL_AUTH_ID"] ??
null,
3763 if (intval(
$ar[
"ID"]) !== intval(
$ID))
3775 if ($phoneRequired &&
$arFields[
"PHONE_NUMBER"] ==
'')
3777 $resultError .=
GetMessage(
"main_user_check_no_phone") .
"<br>";
3787 $primary = (
$ID ===
false ? [] : [
"USER_ID" =>
$ID]);
3788 $field->validateValue($phoneNumber, $primary, [],
$result);
3791 $resultError .= implode(
"<br>",
$result->getErrorMessages());
3800 foreach (
$arFields[
"GROUP_ID"] as $arGroup)
3802 if ($arGroup[
"DATE_ACTIVE_FROM"] !=
'' && !
CheckDateTime($arGroup[
"DATE_ACTIVE_FROM"]))
3804 $error = str_replace(
"#GROUP_ID#", $arGroup[
"GROUP_ID"],
GetMessage(
"WRONG_DATE_ACTIVE_FROM"));
3805 $resultError .=
$error .
"<br>";
3808 if ($arGroup[
"DATE_ACTIVE_TO"] !=
'' && !
CheckDateTime($arGroup[
"DATE_ACTIVE_TO"]))
3810 $error = str_replace(
"#GROUP_ID#", $arGroup[
"GROUP_ID"],
GetMessage(
"WRONG_DATE_ACTIVE_TO"));
3811 $resultError .=
$error .
"<br>";
3817 return $resultError;
3830 $rs->InitFromArray([]);
3834 $userID = (is_object(
$USER) ? intval(
$USER->GetID()) : 0);
3835 if ($userID > 0 &&
$ID == $userID && is_array(self::$CURRENT_USER))
3838 $rs->InitFromArray(self::$CURRENT_USER);
3842 $rs = static::GetList(
'',
'', [
"ID_EQUAL_EXACT" => intval(
$ID)], [
"SELECT" => [
"UF_*"]]);
3843 if ($userID > 0 &&
$ID == $userID)
3845 self::$CURRENT_USER = [
$rs->Fetch()];
3847 $rs->InitFromArray(self::$CURRENT_USER);
3855 $rs = static::GetList(
'id',
'asc', [
"LOGIN_EQUAL_EXACT" => $LOGIN], [
"SELECT" => [
"UF_*"]]);
3898 $saveHistory = (
Option::get(
'main',
'user_profile_history') ===
'Y');
3904 $rUser = static::GetByID(
$ID);
3905 $arUser = $rUser->Fetch();
3908 $originalPassword =
'';
3909 $passwordChanged =
false;
3912 $originalPassword =
$arFields[
"PASSWORD"];
3920 UserStoredAuthTable::deleteByFilter([
'=USER_ID' =>
$ID]);
3922 $passwordChanged =
true;
3926 if (
Option::get(
'main',
'event_log_password_change',
'N') ===
'Y')
3931 if (!isset(
$arFields[
'PASSWORD_EXPIRED']))
3956 $arFields[
"~CHECKWORD_TIME"] =
$DB->CurrentTimeFunction();
3970 array_key_exists(
"PERSONAL_PHOTO",
$arFields)
3971 && is_array(
$arFields[
"PERSONAL_PHOTO"])
3973 !array_key_exists(
"MODULE_ID",
$arFields[
"PERSONAL_PHOTO"])
3974 ||
$arFields[
"PERSONAL_PHOTO"][
"MODULE_ID"] ==
''
3978 $arFields[
"PERSONAL_PHOTO"][
"MODULE_ID"] =
'main';
3981 CFile::SaveForDB(
$arFields,
'PERSONAL_PHOTO',
'main');
3984 array_key_exists(
"WORK_LOGO",
$arFields)
3987 !array_key_exists(
"MODULE_ID",
$arFields[
"WORK_LOGO"])
3988 ||
$arFields[
"WORK_LOGO"][
"MODULE_ID"] ==
''
3992 $arFields[
"WORK_LOGO"][
"MODULE_ID"] =
'main';
3995 CFile::SaveForDB(
$arFields,
'WORK_LOGO',
'main');
4001 $strUpdate .= ($strUpdate !=
'' ?
',' :
'') .
" TIMESTAMP_X = " .
$DB->GetNowFunction();
4004 $strSql =
"UPDATE b_user SET " . $strUpdate .
" WHERE ID=" .
$ID;
4006 $DB->Query($strSql);
4012 $numberExists =
false;
4019 "=PHONE_NUMBER" =>
$arFields[
"PHONE_NUMBER"],
4022 if (
$arFields[
"PHONE_NUMBER"] ==
'' || !$numberExists)
4031 "PHONE_NUMBER" =>
$arFields[
"PHONE_NUMBER"],
4037 if (
Option::get(
'main',
'event_log_user_edit',
'N') ===
'Y')
4047 if ($arUser && $passwordChanged)
4049 if (
Option::get(
'main',
'use_digest_auth',
'N') ==
'Y')
4052 static::UpdateDigest($arUser[
"ID"], $originalPassword);
4056 UserPasswordTable::add([
4057 "USER_ID" => $arUser[
"ID"],
4063 if ($arUser && $authActions)
4065 $authAction =
false;
4066 if (isset(
$arFields[
"ACTIVE"]) && $arUser[
"ACTIVE"] ==
'Y' &&
$arFields[
"ACTIVE"] ==
'N')
4071 $internalUser =
true;
4072 if (isset(
$arFields[
"EXTERNAL_AUTH_ID"]))
4074 if (
$arFields[
"EXTERNAL_AUTH_ID"] !=
'')
4076 $internalUser =
false;
4079 elseif ($arUser[
"EXTERNAL_AUTH_ID"] !=
'')
4081 $internalUser =
false;
4084 if ($internalUser && isset(
$arFields[
"PASSWORD"]) && $passwordChanged)
4090 $USER->SetParam(
"AUTH_ACTION_SKIP_LOGOUT",
true);
4106 static $arSessFields = [
4110 'FIRST_NAME' =>
'NAME',
4111 'SECOND_NAME' =>
'SECOND_NAME',
4112 'LAST_NAME' =>
'LAST_NAME',
4113 'PERSONAL_PHOTO' =>
'PERSONAL_PHOTO',
4114 'PERSONAL_GENDER' =>
'PERSONAL_GENDER',
4115 'AUTO_TIME_ZONE' =>
'AUTO_TIME_ZONE',
4116 'TIME_ZONE' =>
'TIME_ZONE',
4118 foreach ($arSessFields as
$key =>
$val)
4126 $last_name =
$USER->GetParam(
"LAST_NAME");
4127 $USER->SetParam(
"NAME",
$name . (
$name ==
'' || $last_name ==
'' ?
'' :
' ') . $last_name);
4130 self::$CURRENT_USER =
false;
4133 if ($saveHistory && $arUser)
4135 $rUser = static::GetByID(
$ID);
4136 $newUser = $rUser->Fetch();
4145 foreach (
GetModuleEvents(
'main',
'OnAfterUserUpdate',
true) as $arEvent)
4157 if (defined(
"BX_COMP_MANAGED_CACHE"))
4173 $USER_ID = intval($USER_ID);
4181 $prevGroups = static::GetCurrentGroups($USER_ID);
4189 if (!is_array($group))
4191 $group = [
"GROUP_ID" => $group];
4194 $groupId = intval($group[
"GROUP_ID"]);
4195 if ($groupId > 0 && $groupId != 2 && !isset($groupFields[$groupId]))
4197 $inserted[$groupId] = [
4198 "GROUP_ID" => $group[
"GROUP_ID"],
4199 "DATE_ACTIVE_FROM" => (!empty($group[
"DATE_ACTIVE_FROM"]) ? $group[
"DATE_ACTIVE_FROM"] :
null),
4200 "DATE_ACTIVE_TO" => (!empty($group[
"DATE_ACTIVE_TO"]) ? $group[
"DATE_ACTIVE_TO"] :
null),
4202 $groupFields[$groupId] = [
4203 "USER_ID" => $USER_ID,
4204 "GROUP_ID" => $group[
"GROUP_ID"],
4214 UserGroupTable::deleteByFilter([
'=USER_ID' => $USER_ID]);
4216 if (!empty($groupFields))
4218 UserGroupTable::addInsertIgnoreMulti($groupFields,
true);
4223 static::clearUserGroupCache($USER_ID);
4225 foreach (
GetModuleEvents(
'main',
'OnAfterSetUserGroup',
true) as $arEvent)
4230 if ($prevGroups != $inserted)
4237 foreach ($inserted as $group)
4239 foreach ([
"DATE_ACTIVE_FROM",
"DATE_ACTIVE_TO"] as $field)
4241 if ($group[$field] !=
'')
4244 if ($date->getTimestamp() > $now->getTimestamp())
4257 if (
Option::get(
'main',
'event_log_user_groups',
'N') ===
'Y')
4283 if (!is_array($group))
4285 $group = [
"GROUP_ID" => $group];
4287 $groupId = (int)$group[
"GROUP_ID"];
4292 || array_key_exists(
"DATE_ACTIVE_FROM", $group) && $group[
"DATE_ACTIVE_FROM"] !=
$arGroups[$groupId][
"DATE_ACTIVE_FROM"]
4293 || array_key_exists(
"DATE_ACTIVE_TO", $group) && $group[
"DATE_ACTIVE_TO"] !=
$arGroups[$groupId][
"DATE_ACTIVE_TO"]
4323 $groupId = (int)$groupId;
4324 if ($groupId != 2 && !($groupId == 1 &&
$userId == 1))
4347 while ($group =
$res->Fetch())
4349 if ($group[
"GROUP_ID"] != 2)
4351 $groups[(int)$group[
"GROUP_ID"]] = $group;
4363 $r =
$DB->Query(
"SELECT COUNT('x') as C FROM (SELECT ID from b_user limit " . intval(
$maxCount) .
") t");
4367 $r =
$DB->Query(
"SELECT COUNT('x') as C FROM b_user");
4370 return intval($r[
"C"]);
4379 $rsUser =
$DB->Query(
"
4380 SELECT ID, LOGIN, NAME, LAST_NAME, EXTERNAL_AUTH_ID, PERSONAL_PHOTO, WORK_LOGO
4385 $arUser = $rsUser->Fetch();
4393 foreach ($events as $arEvent)
4397 $err =
GetMessage(
"MAIN_BEFORE_DEL_ERR1") .
' ' . ($arEvent[
'TO_MODULE_ID'] ??
'');
4400 $err .=
': ' . $ex->GetString();
4404 if (
Option::get(
'main',
'event_log_user_delete',
'N') ===
'Y')
4412 if ($arUser[
'PERSONAL_PHOTO'] > 0)
4414 CFile::Delete($arUser[
'PERSONAL_PHOTO']);
4416 if ($arUser[
'WORK_LOGO'] > 0)
4418 CFile::Delete($arUser[
'WORK_LOGO']);
4421 CAccess::OnUserDelete(
$ID);
4423 $userFilter = [
'=USER_ID' =>
$ID];
4425 UserGroupTable::deleteByFilter($userFilter);
4427 $DB->Query(
"DELETE FROM b_user_digest WHERE USER_ID=" .
$ID);
4429 ApplicationPasswordTable::deleteByFilter($userFilter);
4439 UserPasswordTable::deleteByFilter($userFilter);
4441 UserStoredAuthTable::deleteByFilter($userFilter);
4443 UserHitAuthTable::deleteByFilter($userFilter);
4445 UserDeviceTable::deleteByFilter($userFilter);
4449 if (
Option::get(
'main',
'event_log_user_delete',
'N') ===
'Y')
4454 if (!
$DB->Query(
"DELETE FROM b_user WHERE ID=" .
$ID .
" AND ID<>1"))
4459 if (defined(
"BX_COMP_MANAGED_CACHE"))
4462 static::clearTagCache(
$ID, $isRealUser);
4465 static::clearUserGroupCache(
$ID);
4469 UserProfileHistoryTable::deleteByFilter($userFilter);
4471 if (
Option::get(
'main',
'user_profile_history') ===
'Y')
4478 foreach (
GetModuleEvents(
'main',
'OnAfterUserDelete',
true) as $arEvent)
4489 foreach (
GetModuleEvents(
'main',
'OnExternalAuthList',
true) as $arEvent)
4502 $result->InitFromArray($arAll);
4508 $policy = static::getPolicy($iUserId);
4515 if (
$arPolicy[
"PASSWORD_UPPERCASE"] ===
'Y')
4519 if (
$arPolicy[
"PASSWORD_LOWERCASE"] ===
'Y')
4523 if (
$arPolicy[
"PASSWORD_DIGITS"] ===
'Y')
4527 if (
$arPolicy[
"PASSWORD_PUNCTUATION"] ===
'Y')
4529 $ar[] =
GetMessage(
"MAIN_GP_PASSWORD_PUNCTUATION", [
"#SPECIAL_CHARS#" => static::PASSWORD_SPECIAL_CHARS]);
4531 $arPolicy[
"PASSWORD_REQUIREMENTS"] = implode(
", ",
$ar) .
".";
4545 if (isset($cache[$cacheId]))
4547 return $cache[$cacheId];
4553 'select' => [
'GROUP_ID' =>
'ID',
'SECURITY_POLICY'],
4554 'filter' => [
'=ID' => 2],
4555 'cache' => [
'ttl' => 86400],
4557 $group2Policy =
$res->Fetch();
4561 $arPolicies[] = $group2Policy;
4569 $value = intval($value);
4570 if ($value > 0 && $value != 2)
4578 'select' => [
'GROUP_ID' =>
'ID',
'SECURITY_POLICY'],
4583 'cache' => [
'ttl' => 86400],
4586 while ($row =
$result->fetch())
4588 $arPolicies[] = $row;
4599 'select' => [
'GROUP_ID' =>
'ID',
'SECURITY_POLICY'],
4601 '=UserGroup:GROUP.USER_ID' =>
$userId,
4605 '=UserGroup:GROUP.DATE_ACTIVE_FROM' =>
null,
4606 '<=UserGroup:GROUP.DATE_ACTIVE_FROM' => $nowTimeExpression,
4610 '=UserGroup:GROUP.DATE_ACTIVE_TO' =>
null,
4611 '>=UserGroup:GROUP.DATE_ACTIVE_TO' => $nowTimeExpression,
4616 while ($row =
$result->fetch())
4618 $arPolicies[] = $row;
4625 foreach ($arPolicies as
$ar)
4627 if (
$ar[
"SECURITY_POLICY"])
4629 $arGroupPolicy = unserialize(
$ar[
"SECURITY_POLICY"], [
'allowed_classes' =>
false]);
4636 if (!is_array($arGroupPolicy))
4641 foreach ($arGroupPolicy as
$key =>
$val)
4643 $rule = $policy[
$key];
4646 if ($rule->assignValue(
$val))
4649 $rule->setGroupId((
int)
$ar[
'GROUP_ID']);
4655 if (
count($cache) <= 10)
4657 $cache[$cacheId] = $policy;
4675 $res = UserStoredAuthTable::query()
4677 ->where(
'USER_ID',
$context->getUserId())
4678 ->setOrder([
'LAST_AUTH' =>
'DESC'])
4682 $policy = static::getPolicy(
$context->getUserId());
4684 $maxStoreNum = $policy->getMaxStoreNum();
4685 $storeTimeout = $policy->getStoreTimeout();
4686 $sessionTimeout = $policy->getSessionTimeout();
4687 $storeIpMask = ip2long($policy->getStoreIpMask());
4689 $ipAddress = Main\Context::getCurrent()->getServer()->getRemoteAddr();
4693 if (
$ar[
"TEMP_HASH"] ==
'N')
4701 $lastAuthTime =
$ar[
"LAST_AUTH"]->getTimestamp();
4706 || (
$ar[
"TEMP_HASH"] ==
'N' && time() - ($storeTimeout * 60) > $lastAuthTime)
4707 || (
$ar[
"TEMP_HASH"] ==
'Y' && time() - ($sessionTimeout * 60) > $lastAuthTime)
4710 UserStoredAuthTable::delete(
$ar[
'ID']);
4715 if (!$tempHash ||
$ar[
"TEMP_HASH"] ==
'Y')
4717 $remote_net = $storeIpMask & ip2long($ipAddress);
4718 $stored_net = $storeIpMask & (float)
$ar[
"IP_ADDR"];
4720 if (
$hash ===
$ar[
"STORED_HASH"] && $remote_net == $stored_net)
4722 $hashId =
$ar[
"ID"];
4725 ->setStoredAuthId($hashId)
4726 ->setStoredAuthHash(
$hash)
4727 ->setMethod(Method::Cookie)
4742 $userGroups =
"2," . implode(
",", array_map(
"intval",
$arGroups));
4750 SELECT O.NAME OPERATION_NAME
4751 FROM b_group_task GT
4752 INNER JOIN b_task_operation T_O ON T_O.TASK_ID=GT.TASK_ID
4753 INNER JOIN b_operation O ON O.ID=T_O.OPERATION_ID
4754 WHERE GT.GROUP_ID IN(" . $userGroups .
")
4756 SELECT O.NAME OPERATION_NAME
4758 INNER JOIN b_task_operation T_O ON T_O.TASK_ID=" .
$DB->ToNumber(
"OP.VALUE") .
"
4759 INNER JOIN b_operation O ON O.ID=T_O.OPERATION_ID
4760 WHERE OP.NAME='GROUP_DEFAULT_TASK'
4762 SELECT O.NAME OPERATION_NAME
4764 INNER JOIN b_task T ON T.MODULE_ID=OP.MODULE_ID AND T.BINDING='module' AND T.LETTER=" .
$DB->ToChar(
"OP.VALUE", 1) .
" AND T.SYS='Y'
4765 INNER JOIN b_task_operation T_O ON T_O.TASK_ID=T.ID
4766 INNER JOIN b_operation O ON O.ID=T_O.OPERATION_ID
4767 WHERE OP.NAME='GROUP_DEFAULT_RIGHT'
4770 $z =
$DB->Query($sql_str);
4772 while ($r =
$z->Fetch())
4774 $arr[$r[
'OPERATION_NAME']] = $r[
'OPERATION_NAME'];
4796 return isset($op[$op_name]);
4805 if (!isset(static::$kernelSession[
"SESS_OPERATIONS"]))
4810 return isset(static::$kernelSession[
"SESS_OPERATIONS"][$op_name]);
4820 $arFileOperations = [];
4821 foreach ($permissions as $taskId)
4825 $arFileOperations = array_values(array_unique($arFileOperations));
4827 return $arFileOperations;
4839 if (!$USER->CanDoOperation(
'edit_php'))
4848 static $fileOperations = [];
4851 if (!isset($fileOperations[
$key]))
4856 return in_array($op_name, $fileOperations[
$key]);
4873 if (
$USER->CanDoFileOperation(
'fm_view_file', [
$site ??
false,
$path]))
4885 if ($entity_id ==
"USER" &&
$USER->CanDoOperation(
'edit_other_settings'))
4912 if (trim(
$code) !=
'')
4952 $cleanup_days = (int)
Option::get(
'main',
'new_user_registration_cleanup_days', 7);
4953 if ($cleanup_days > 0)
4956 $date->add(
"-{$cleanup_days}D");
4958 if (
Option::get(
'main',
'new_user_registration_email_confirmation',
'N') ===
'Y')
4962 "!CONFIRM_CODE" =>
false,
4964 "<DATE_REGISTER" => $date,
4970 while (
$user = $users->fetch())
4972 static::Delete(
$user[
"ID"]);
4976 if (
Option::get(
'main',
'new_user_phone_auth',
'N') ===
'Y')
4980 '=\Bitrix\Main\UserPhoneAuthTable:USER.CONFIRMED' =>
'N',
4982 "<DATE_REGISTER" => $date,
4988 while (
$user = $users->fetch())
4990 static::Delete(
$user[
"ID"]);
4995 $historyCleanupDays = (int)
Option::get(
'main',
'profile_history_cleanup_days', 0);
4996 if ($historyCleanupDays > 0)
4999 $date->add(
"-{$historyCleanupDays}D");
5000 UserProfileHistoryTable::deleteByFilter([
"<DATE_INSERT" => $date]);
5003 $deviceCleanupDays = (int)
Option::get(
'main',
'device_history_cleanup_days', 180);
5004 if ($deviceCleanupDays > 0)
5007 $date->add(
"-{$deviceCleanupDays}D");
5008 UserDeviceLoginTable::deleteByFilter([
"<LOGIN_DATE" => $date]);
5011 return "CUser::CleanUpAgent();";
5016 $blockDays = (int)
Option::get(
'main',
'inactive_users_block_days', 0);
5019 $log = (
Option::get(
'main',
'event_log_block_user',
'N') ===
'Y');
5021 $userObj =
new CUser();
5024 $date->add(
"-{$blockDays}D");
5029 "<LAST_LOGIN" => $date,
5035 while (
$user = $users->fetch())
5043 $userObj->Update(
$user[
"ID"], [
"BLOCKED" =>
'Y'],
false);
5052 return "CUser::DeactivateAgent();";
5090 if (intval(
$USER->GetParam(
'SET_LAST_ACTIVITY')) + 60 > time())
5096 $USER->SetParam(
'PREV_LAST_ACTIVITY',
$USER->GetParam(
'SET_LAST_ACTIVITY'));
5097 $USER->SetParam(
'SET_LAST_ACTIVITY', time());
5100 static::SetLastActivityDateByArray([
$userId],
$_SERVER[
'REMOTE_ADDR']);
5109 if (!is_array($arUsers) || empty($arUsers))
5114 $strSqlPrefix =
"UPDATE b_user SET " .
5115 "TIMESTAMP_X = TIMESTAMP_X, " .
5116 "LAST_ACTIVITY_DATE = " .
$DB->CurrentTimeFunction() .
" WHERE ID IN (";
5117 $strSqlPostfix =
")";
5118 $maxValuesLen = 2048;
5121 $arUsers = array_map(
"intval", $arUsers);
5124 $strSqlValues .=
",$userId";
5125 if (mb_strlen($strSqlValues) > $maxValuesLen)
5127 $DB->Query($strSqlPrefix . mb_substr($strSqlValues, 1) . $strSqlPostfix,
false,
'', [
"ignore_dml" =>
true]);
5132 if ($strSqlValues !=
'')
5134 $DB->Query($strSqlPrefix . mb_substr($strSqlValues, 1) . $strSqlPostfix,
false,
'', [
"ignore_dml" =>
true]);
5137 $event =
new Main\Event(
'main',
'OnUserSetLastActivityDate', [$arUsers, $ip]);
5159 $lastseen = $lastseen->getTimestamp();
5163 if (is_int($lastseen))
5165 $lastseen = intval($lastseen);
5181 $now = $now->getTimestamp();
5185 $now = intval($now);
5190 'IS_ONLINE' =>
false,
5191 'STATUS' => self::STATUS_OFFLINE,
5192 'STATUS_TEXT' =>
GetMessage(
'USER_STATUS_OFFLINE'),
5193 'LAST_SEEN' => $lastseen,
5194 'LAST_SEEN_TEXT' =>
'',
5198 if ($lastseen ===
false)
5203 $result[
'IS_ONLINE'] = $now - $lastseen <= static::GetSecondsForLimitOnline();
5204 $result[
'STATUS'] =
$result[
'IS_ONLINE'] ? self::STATUS_ONLINE : self::STATUS_OFFLINE;
5207 if ($lastseen && $now - $lastseen > 300)
5209 $result[
'LAST_SEEN_TEXT'] = static::FormatLastActivityDate($lastseen, $now);
5216 foreach (
GetModuleEvents(
'main',
'OnUserOnlineStatusGetCustomOnlineStatus',
true) as $arEvent)
5219 if (is_array($customStatus))
5221 if (!empty($customStatus[
'STATUS']) && !empty($customStatus[
'STATUS_TEXT']))
5223 $result[
'STATUS'] = strtolower($customStatus[
'STATUS']);
5224 $result[
'STATUS_TEXT'] = $customStatus[
'STATUS_TEXT'];
5226 if (isset($customStatus[
'LAST_SEEN']) && intval($customStatus[
'LAST_SEEN']) > 0)
5228 $result[
'LAST_SEEN'] = intval($customStatus[
'LAST_SEEN']);
5230 if (isset($customStatus[
'LAST_SEEN_TEXT']))
5232 $result[
'LAST_SEEN_TEXT'] = $customStatus[
'LAST_SEEN_TEXT'];
5239 foreach (
GetModuleEvents(
'main',
'OnUserOnlineStatusGetCustomOfflineStatus',
true) as $arEvent)
5242 if (is_array($customStatus))
5244 if (!empty($customStatus[
'STATUS']) && !empty($customStatus[
'STATUS_TEXT']))
5246 $result[
'STATUS'] = strtolower($customStatus[
'STATUS']);
5247 $result[
'STATUS_TEXT'] = $customStatus[
'STATUS_TEXT'];
5249 if (isset($customStatus[
'LAST_SEEN']) && intval($customStatus[
'LAST_SEEN']) > 0)
5251 $result[
'LAST_SEEN'] = intval($customStatus[
'LAST_SEEN']);
5253 if (isset($customStatus[
'LAST_SEEN_TEXT']))
5255 $result[
'LAST_SEEN_TEXT'] = $customStatus[
'LAST_SEEN_TEXT'];
5275 if ($timestamp instanceof
DateTime)
5277 $timestamp = $timestamp->getTimestamp();
5281 if (is_int($timestamp))
5283 $timestamp = intval($timestamp);
5299 $now = $now->getTimestamp();
5303 $now = intval($now);
5311 "tomorrow" =>
"#01#{$timeFormat}",
5313 "todayFuture" =>
"#03#{$timeFormat}",
5314 "yesterday" =>
"#04#{$timeFormat}",
5315 "-" => preg_replace(
'/:s$/',
'',
$DB->DateFormatToPHP(CSite::GetDateFormat())),
5319 "H24" =>
"#03#{$timeFormat}",
5324 ], $timestamp, $now);
5326 if (preg_match(
'/^#(\d+)#(.*)/', $formattedDate, $match))
5331 $formattedDate = str_replace(
"#TIME#", $match[2],
GetMessage(
'USER_LAST_SEEN_TOMORROW'));
5334 $formattedDate =
GetMessage(
'USER_LAST_SEEN_NOW');
5337 $formattedDate = str_replace(
"#TIME#", $match[2],
GetMessage(
'USER_LAST_SEEN_TODAY'));
5340 $formattedDate = str_replace(
"#TIME#", $match[2],
GetMessage(
'USER_LAST_SEEN_YESTERDAY'));
5343 $formattedDate =
GetMessage(
'USER_LAST_SEEN_MORE_YEAR');
5346 $formattedDate = $match[2];
5351 return $formattedDate;
5359 foreach ($arName as $s)
5364 $arNameReady[] = $s;
5368 if (empty($arNameReady))
5373 $strSqlWhereEMail = ((
$email !=
'') ?
" AND upper(U.EMAIL) = upper('" .
$DB->ForSql(
$email) .
"') " :
'');
5377 if (
count($arNameReady) > 3)
5380 "SELECT U.ID, U.NAME, U.LAST_NAME, U.SECOND_NAME, U.LOGIN, U.EMAIL " .
5384 for (
$i = 0;
$i < 4;
$i++)
5386 for ($j = 0; $j < 4; $j++)
5393 for (
$k = 0;
$k < 4;
$k++)
5395 if (
$i ==
$k || $j ==
$k)
5400 for (
$l = 0;
$l < 4;
$l++)
5412 $strSql .=
"(U.NAME IS NOT NULL AND upper(U.NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5413 "AND U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%') " .
5414 "AND U.LOGIN IS NOT NULL AND upper(U.LOGIN) LIKE upper('" .
$DB->ForSql($arNameReady[
$k]) .
"%') " .
5415 "AND U.EMAIL IS NOT NULL AND upper(U.EMAIL) LIKE upper('" .
$DB->ForSql($arNameReady[
$l]) .
"%'))";
5424 elseif (Count($arNameReady) == 3)
5427 "SELECT U.ID, U.NAME, U.LAST_NAME, U.SECOND_NAME, U.LOGIN, U.EMAIL " .
5431 for (
$i = 0;
$i < 3;
$i++)
5433 for ($j = 0; $j < 3; $j++)
5440 for (
$k = 0;
$k < 3;
$k++)
5442 if (
$i ==
$k || $j ==
$k)
5453 $strSql .=
"(U.NAME IS NOT NULL AND upper(U.NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5454 "AND U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%') " .
5455 "AND U.LOGIN IS NOT NULL AND upper(U.LOGIN) LIKE upper('" .
$DB->ForSql($arNameReady[
$k]) .
"%'))";
5457 $strSql .=
"(U.NAME IS NOT NULL AND upper(U.NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5458 "AND U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%') " .
5459 "AND U.EMAIL IS NOT NULL AND upper(U.EMAIL) LIKE upper('" .
$DB->ForSql($arNameReady[
$k]) .
"%'))";
5461 $strSql .=
"(U.NAME IS NOT NULL AND upper(U.NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5462 "AND U.LOGIN IS NOT NULL AND upper(U.LOGIN) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%') " .
5463 "AND U.EMAIL IS NOT NULL AND upper(U.EMAIL) LIKE upper('" .
$DB->ForSql($arNameReady[
$k]) .
"%'))";
5465 $strSql .=
"(U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5466 "AND U.LOGIN IS NOT NULL AND upper(U.LOGIN) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%') " .
5467 "AND U.EMAIL IS NOT NULL AND upper(U.EMAIL) LIKE upper('" .
$DB->ForSql($arNameReady[
$k]) .
"%'))";
5476 elseif (Count($arNameReady) == 2)
5479 "SELECT U.ID, U.NAME, U.LAST_NAME, U.SECOND_NAME, U.LOGIN, U.EMAIL " .
5483 for (
$i = 0;
$i < 2;
$i++)
5485 for ($j = 0; $j < 2; $j++)
5498 $strSql .=
"(U.NAME IS NOT NULL AND upper(U.NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5499 "AND U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%'))";
5501 $strSql .=
"(U.NAME IS NOT NULL AND upper(U.NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5502 "AND U.LOGIN IS NOT NULL AND upper(U.LOGIN) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%'))";
5504 $strSql .=
"(U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5505 "AND U.LOGIN IS NOT NULL AND upper(U.LOGIN) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%'))";
5507 $strSql .=
"(U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5508 "AND U.EMAIL IS NOT NULL AND upper(U.EMAIL) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%'))";
5510 $strSql .=
"(U.NAME IS NOT NULL AND upper(U.NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5511 "AND U.EMAIL IS NOT NULL AND upper(U.EMAIL) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%'))";
5513 $strSql .=
"(U.LOGIN IS NOT NULL AND upper(U.LOGIN) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5514 "AND U.EMAIL IS NOT NULL AND upper(U.EMAIL) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%'))";
5524 "SELECT U.ID, U.NAME, U.LAST_NAME, U.SECOND_NAME, U.LOGIN, U.EMAIL " .
5526 "WHERE (U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[0]) .
"%') " .
5527 " OR U.LOGIN IS NOT NULL AND upper(U.LOGIN) LIKE upper('" .
$DB->ForSql($arNameReady[0]) .
"%') " .
5528 " OR U.EMAIL IS NOT NULL AND upper(U.EMAIL) LIKE upper('" .
$DB->ForSql($arNameReady[0]) .
"%') " .
5529 " OR U.NAME IS NOT NULL AND upper(U.NAME) LIKE upper('" .
$DB->ForSql($arNameReady[0]) .
"%')) ";
5531 $strSql .= $strSqlWhereEMail;
5535 if (Count($arNameReady) >= 3)
5538 "SELECT U.ID, U.NAME, U.LAST_NAME, U.SECOND_NAME, U.LOGIN, U.EMAIL " .
5542 for (
$i = 0;
$i < 3;
$i++)
5544 for ($j = 0; $j < 3; $j++)
5551 for (
$k = 0;
$k < 3;
$k++)
5553 if (
$i ==
$k || $j ==
$k)
5563 $strSql .=
"(U.NAME IS NOT NULL AND upper(U.NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5564 "AND U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%') " .
5565 "AND U.SECOND_NAME IS NOT NULL AND upper(U.SECOND_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$k]) .
"%')" . $strSqlWhereEMail .
")";
5572 elseif (Count($arNameReady) == 2)
5575 "SELECT U.ID, U.NAME, U.LAST_NAME, U.SECOND_NAME, U.LOGIN, U.EMAIL " .
5579 for (
$i = 0;
$i < 2;
$i++)
5581 for ($j = 0; $j < 2; $j++)
5593 $strSql .=
"(U.NAME IS NOT NULL AND upper(U.NAME) LIKE upper('" .
$DB->ForSql($arNameReady[
$i]) .
"%') " .
5594 "AND U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[$j]) .
"%')" . $strSqlWhereEMail .
")";
5603 "SELECT U.ID, U.NAME, U.LAST_NAME, U.SECOND_NAME, U.LOGIN, U.EMAIL " .
5605 "WHERE U.LAST_NAME IS NOT NULL AND upper(U.LAST_NAME) LIKE upper('" .
$DB->ForSql($arNameReady[0]) .
"%') " .
5614 public static function FormatName($NAME_TEMPLATE, $arUser, $bUseLogin =
false, $bHTMLSpec =
true, $enabledEmptyNameStub =
true)
5616 if (isset($arUser[
"ID"]))
5618 $ID = intval($arUser[
'ID']);
5625 $NAME_SHORT = (($arUser[
'NAME'] ??
'') !=
'' ? mb_substr($arUser[
'NAME'], 0, 1) .
'.' :
'');
5626 $LAST_NAME_SHORT = (($arUser[
'LAST_NAME'] ??
'') !=
'' ? mb_substr($arUser[
'LAST_NAME'], 0, 1) .
'.' :
'');
5627 $SECOND_NAME_SHORT = (($arUser[
'SECOND_NAME'] ??
'') !=
'' ? mb_substr($arUser[
'SECOND_NAME'], 0, 1) .
'.' :
'');
5630 [
'#TITLE#',
'#NAME#',
'#LAST_NAME#',
'#SECOND_NAME#',
'#NAME_SHORT#',
'#LAST_NAME_SHORT#',
'#SECOND_NAME_SHORT#',
'#EMAIL#',
'#ID#'],
5631 [($arUser[
'TITLE'] ??
''), ($arUser[
'NAME'] ??
''), ($arUser[
'LAST_NAME'] ??
''), ($arUser[
'SECOND_NAME'] ??
''), $NAME_SHORT, $LAST_NAME_SHORT, $SECOND_NAME_SHORT, ($arUser[
'EMAIL'] ??
''),
$ID],
5635 while (str_contains(
$res,
' '))
5637 $res = str_replace(
' ',
' ',
$res);
5642 if (str_contains($NAME_TEMPLATE,
'#NAME#') || str_contains($NAME_TEMPLATE,
'#NAME_SHORT#'))
5644 $res_check .= $arUser[
'NAME'] ??
'';
5646 if (str_contains($NAME_TEMPLATE,
'#LAST_NAME#') || str_contains($NAME_TEMPLATE,
'#LAST_NAME_SHORT#'))
5648 $res_check .= $arUser[
'LAST_NAME'] ??
'';
5650 if (str_contains($NAME_TEMPLATE,
'#SECOND_NAME#') || str_contains($NAME_TEMPLATE,
'#SECOND_NAME_SHORT#'))
5652 $res_check .= $arUser[
'SECOND_NAME'] ??
'';
5655 if (trim($res_check) ==
'')
5657 if ($bUseLogin && !empty($arUser[
'LOGIN']))
5659 $res = $arUser[
'LOGIN'];
5661 elseif ($enabledEmptyNameStub)
5670 if (str_contains($NAME_TEMPLATE,
'[#ID#]'))
5681 $res = str_replace([
'#NOBR#',
'#/NOBR#'],
'',
$res);
5690 self::$userGroupCache = [];
5695 if (isset(self::$userGroupCache[
$ID]))
5697 unset(self::$userGroupCache[
$ID]);
5702 public function CheckAuthActions()
5709 if (!is_array(static::$kernelSession[
"AUTH_ACTIONS_PERFORMED"]))
5711 static::$kernelSession[
"AUTH_ACTIONS_PERFORMED"] = [];
5714 $now =
new DateTime();
5716 $actions = Main\UserAuthActionTable::getList([
5717 "filter" => [
"=USER_ID" => $this->
getContext()->getUserId()],
5718 "order" => [
"USER_ID" =>
"ASC",
"PRIORITY" =>
"ASC",
"ID" =>
"DESC"],
5719 "cache" => [
"ttl" => 3600],
5722 while (
$action = $actions->fetch())
5724 if (isset(static::$kernelSession[
"AUTH_ACTIONS_PERFORMED"][
$action[
"ID"]]))
5737 $actionDate =
$action[
"ACTION_DATE"];
5739 if ($actionDate <= $now)
5742 static::$kernelSession[
"AUTH_ACTIONS_PERFORMED"][
$action[
"ID"]] =
true;
5752 case Main\UserAuthActionTable::ACTION_LOGOUT:
5753 if ($this->
GetParam(
"AUTH_ACTION_SKIP_LOGOUT"))
5756 $this->
SetParam(
"AUTH_ACTION_SKIP_LOGOUT",
false);
5763 case Main\UserAuthActionTable::ACTION_UPDATE:
5778 Main\UserAuthActionTable::deleteByFilter([
"<ACTION_DATE" => $date]);
5779 return 'CUser::AuthActionsCleanUpAgent();';
5789 if ($row && $row[
"OTP_SECRET"] !=
'')
5792 $totp->setInterval(self::PHONE_CODE_OTP_INTERVAL);
5793 $totp->setSecret($row[
"OTP_SECRET"]);
5795 $timecode = $totp->timecode(time());
5796 $code = $totp->generateOTP($timecode);
5803 return [
$code, $row[
"PHONE_NUMBER"]];
5823 if ($row && $row[
"OTP_SECRET"] !=
'')
5825 if ($row[
"ATTEMPTS"] >= 3)
5831 $totp->setInterval(self::PHONE_CODE_OTP_INTERVAL);
5832 $totp->setSecret($row[
"OTP_SECRET"]);
5846 if ($row[
"CONFIRMED"] ==
'N')
5848 $data[
"CONFIRMED"] =
'Y';
5851 $data[
'DATE_SENT'] =
'';
5855 $data[
"ATTEMPTS"] = (int)$row[
"ATTEMPTS"] + 1;
5865 return $row[
"USER_ID"];
5884 $select = [
"USER_ID",
"DATE_SENT",
"USER.LANGUAGE_ID"];
5888 $context = Main\Context::getCurrent();
5900 "=PHONE_NUMBER" => $phoneNumber,
5906 $result->addError(
new Main\
Error(Loc::getMessage(
"main_register_no_user"),
"ERR_NOT_FOUND"));
5911 if ($userPhone->getDateSent())
5914 if (($currentDateTime->getTimestamp() - $userPhone->getDateSent()->getTimestamp()) < static::PHONE_CODE_RESEND_INTERVAL)
5916 $result->addError(
new Main\
Error(Loc::getMessage(
"main_register_timeout"),
"ERR_TIMEOUT"));
5921 [
$code, $phoneNumber] = static::GeneratePhoneCode($userPhone->getUserId());
5925 $siteId = CSite::GetDefSite($userPhone->getUser()->getLid());
5927 $language = $userPhone->getUser()->getLanguageId();
5932 "USER_PHONE" => $phoneNumber,
5938 if ($language !=
'')
5941 $sms->setLanguage($language);
5946 $result->setData([
"USER_ID" => $userPhone->getUserId()]);
5961 $check = $shortCode->checkDateSent();
5963 if ($check->isSuccess())
5965 $code = $shortCode->generate();
5969 $shortCode->saveDateSent();
5973 $result->addError(
new Main\
Error(Loc::getMessage(
"main_register_timeout"),
"ERR_TIMEOUT"));
5976 $result->setData($check->getData());
5987 if ($this->context ===
null)
6004 static $nameFields = [
6005 'NAME',
'LAST_NAME',
'SECOND_NAME',
6006 'ACTIVE',
'LOGIN',
'EMAIL',
6007 'PERSONAL_GENDER',
'PERSONAL_PHOTO',
'WORK_POSITION',
'PERSONAL_PROFESSION',
'PERSONAL_WWW',
'PERSONAL_BIRTHDAY',
'TITLE',
6008 'EXTERNAL_AUTH_ID',
'UF_DEPARTMENT',
6009 'AUTO_TIME_ZONE',
'TIME_ZONE',
'TIME_ZONE_OFFSET',
6016 foreach ($nameFields as
$val)
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getConnection($name="")
static findPassword($userId, $password, $passwordOriginal=true)
static findDigestPassword($userId, array $digest)
static jsonDecode(string $json)
static addLogin(Context $context, array $user)
static exists(string $password, string $path)
static deleteByUser($userId)
static getInstance($moduleId=null)
static get($moduleId, $name, $default="", $siteId=false)
static signData(array $data)
static isModuleInstalled($moduleName)
static getRowById($id, array $parameters=[])
static getList(array $parameters=array())
static update($primary, array $data)
static equals($hash, $password, $original=true)
static hash($password, $salt=null)
static getString($length, $caseSensitive=false)
const ALPHABET_ALPHALOWER
const ALPHABET_ALPHAUPPER
static getStringByAlphabet($length, $alphabet, $requireAll=false)
static createFromUserTime($timeString)
static addUpdateAction($userId, Type\DateTime $date=null)
static addLogoutAction($userId, $applicationId=null)
static addByContext($agreementId, $originatorId=null, $originId=null, array $params=array())
static normalizePhoneNumber($number, $defaultCountry='')
static addHistory($userId, $type, array $before=null, array $after=null)
static getExternalUserTypes()
static getSecondsForLimitOnline()
static shouldReindex(array $fields)
static deleteIndexRecord($id)
static getUserGroupIds($userId)
static verifyUser(array $params)
static setDeferredParams($params)
static getDeferredParams()
static GetSubordinateGroups($grId)
static GetOperations($ID, $return_names=false)
static GetUserGroupList($ID)
static AuthActionsCleanUpAgent()
static clearTagCache(int $ID, bool $realUser, array $fields=null)
static clearUserGroupCache($ID=false)
static GetHitAuthHash($urlMask, $userID=false, $siteId=null)
static GeneratePhoneCode($userId)
static CheckPasswordAgainstPolicy($password, $arPolicy, $userId=null)
static CheckStoredHash($context, $hash, $tempHash=false)
SimpleRegister($USER_EMAIL, $SITE_ID=false)
static GetFileOperations($arPath, $arGroups=false)
ChangePassword($LOGIN, $CHECKWORD, $PASSWORD, $CONFIRM_PASSWORD, $SITE_ID=false, $captcha_word='', $captcha_sid=0, $authActions=true, $phoneNumber='', $currentPassword='')
static FormatLastActivityDate($timestamp, $now=false)
static GetGroupPolicy($iUserId)
static UserTypeRightsCheck($entity_id)
static GetSubordinateGroups(int $userID=null)
static IsOnLine($id, $interval=null)
Authorize($context, $bSave=false, $bUpdate=true, $applicationId=null, $onlyActive=true)
static AddHitAuthHash($url, $user_id=false, $site_id=false, $ttl=null)
static UnblockAgent($userId)
static CheckInternalFields($arFields, $ID=false)
static SendUserInfo($ID, $SITE_ID, $MSG, $bImmediate=false, $eventName="USER_INFO", $checkword=null)
static SendPassword($LOGIN, $EMAIL, $SITE_ID=false, $captcha_word='', $captcha_sid=0, $phoneNumber='', $shortCode=false)
static UpdateDigest($ID, $pass)
static GetExternalUserTypes()
CheckFields(&$arFields, $ID=false)
UpdateSessionData(Authentication\Context $context, $onlyActive=true)
static GetCurrentGroups(int $userId)
const PHONE_CODE_OTP_INTERVAL
static GetList($by='', $order='', $arFilter=[], $arParams=[])
static SendPhoneCode($phoneNumber, $smsTemplate, $siteId=null)
static GetExternalAuthList()
LoginByOtp($otp, $remember_otp='N', $captcha_word='', $captcha_sid='')
static GetUserGroupEx($ID)
static SetLastActivityDate($userId=null, $cache=false)
CanDoFileOperation($op_name, $arPath)
static GetSecondsForLimitOnline()
static VerifyPhoneCode($phoneNumber, $code)
static GetDropDownList($strSqlSearch="and ACTIVE='Y'", $strSqlOrder="ORDER BY ID, NAME, LAST_NAME")
static AppendUserGroup($userId, $groups)
Login($login, $password, $remember='N', $password_original='Y')
static LoginInternal(&$arParams, &$result_message=true, $context=null, &$error=[])
static GetCount($maxCount=0)
static GeneratePasswordByPolicy(array $groups)
LoginByHash($login, $hash)
GetFormattedName($bUseBreaks=true, $bHTMLSpec=true)
static getLogoutParams($deleteParms=[])
static GetOnlineStatus($userId, $lastseen, $now=false)
Register($USER_LOGIN, $USER_NAME, $USER_LAST_NAME, $USER_PASSWORD, $USER_CONFIRM_PASSWORD, $USER_EMAIL, $SITE_ID=false, $captcha_word='', $captcha_sid=0, $bSkipConfirm=false, $USER_PHONE_NUMBER='')
Update($ID, $arFields, $authActions=true)
static SetLastActivityDateByArray($arUsers, $ip=null)
static SearchUserByName($arName, $email='', $bLoginMode=false)
const PHONE_CODE_RESEND_INTERVAL
static CleanUpHitAuthAgent()
const PASSWORD_SPECIAL_CHARS
static GetByLogin($LOGIN)
static FormatName($NAME_TEMPLATE, $arUser, $bUseLogin=false, $bHTMLSpec=true, $enabledEmptyNameStub=true)
static GetActiveUsersCount()
static SendEmailCode($userId, $siteId)
CanDoOperation($op_name, $user_id=0)
LoginHitByHash($hash, $closeSession=true, $delete=false, $remember=false)
AuthorizeWithOtp($user_id, $bSave=false)
GetAllOperations($arGroups=false)
setStoredAuthCookies($login, $hash, $save)
CanAccessFile(string $path, ?string $site=null)
static RemoveUserGroup(int $userId, array $groups)
static getPolicy($userId)
static SetUserGroup($USER_ID, $arGroups, $newUser=false)
SetControllerAdmin($isAdmin=true)
RequiredHTTPAuthBasic($Realm="Bitrix")
static blockUser($userId, $blockTime, $loginAttempts)
static Log($SEVERITY, $AUDIT_TYPE_ID, $MODULE_ID, $ITEM_ID, $DESCRIPTION=false, $SITE_ID=false)
static OnUserDelete($user_id)
static OnAfterSetUserGroup($USER_ID, $groups)
static DeleteByUser($USER_ID)
SetEntity($entity_id, $ID)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
global $USER_FIELD_MANAGER
$_SERVER["DOCUMENT_ROOT"]
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
if(file_exists(( $_fname=__DIR__ . "/classes/general/update_db_updater.php"))) if(($_fname=getLocalPath("init.php")) !==false) if(( $_fname=getLocalPath("php_interface/init.php", BX_PERSONAL_ROOT)) !==false) if(($_fname=getLocalPath("php_interface/" . SITE_ID . "/init.php", BX_PERSONAL_ROOT)) !==false) if((!(defined("STATISTIC_ONLY") &&STATISTIC_ONLY &&!str_starts_with( $GLOBALS["APPLICATION"]->GetCurPage(), BX_ROOT . "/admin/"))) &&COption::GetOptionString("main", "include_charset", "Y")=="Y" &&LANG_CHARSET !='') if(COption::GetOptionString("main", "set_p3p_header", "Y")=="Y") $license
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
IsAmPmMode($returnConst=false)
ExecuteModuleEventEx($arEvent, $arParams=[])
setSessionExpired($pIsExpired=true)
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
HasScriptExtension($check_name)
FmtDate($str_date, $format=false, $site=false, $bSearchInSitesOnly=false)
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
check_email($email, $strict=false, $domainCheck=false)
IsConfigFile(string $path)
CheckDateTime($datetime, $format=false)
MkDateTime($strDT, $format="d.m.Y H:i:s")
MakeTimeStamp($datetime, $format=false)
bitrix_sessid_get($varname='sessid')
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"