- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/user.php
- Класс: CAllUser
- Вызов: CAllUser::LoginHitByHash
public function LoginHitByHash($hash, $closeSession = true, $delete = false, $remember = false)
{
global $APPLICATION;
$hash = trim($hash);
if ($hash == '')
{
return false;
}
$APPLICATION->ResetException();
$request = MainContext::getCurrent()->getRequest();
$url = str_replace('%', '%%', $request->getRequestedPage());
$connection = MainApplication::getConnection();
$helper = $connection->getSqlHelper();
$query = UserHitAuthTable::query()
->setSelect(['ID', 'USER_ID', 'HASH', 'VALID_UNTIL'])
->where('USER.ACTIVE', 'Y')
->where('USER.BLOCKED', 'N')
->where('HASH', $hash)
->whereExpr("%s = left('" . $helper->forSql($url) . "', length(%s))", ['URL', 'URL'])
;
if (!defined("ADMIN_SECTION") || ADMIN_SECTION !== true)
{
$query->where('SITE_ID', SITE_ID);
}
if ($hashData = $query->fetch())
{
// case sensitive
if ($hashData['HASH'] === $hash)
{
if ($hashData['VALID_UNTIL'] instanceof MainTypeDateTime)
{
if ((new MainTypeDateTime())->getTimestamp() > $hashData['VALID_UNTIL']->getTimestamp())
{
UserHitAuthTable::delete($hashData['ID']);
return false;
}
}
setSessionExpired($closeSession);
$context = (new AuthenticationContext())
->setUserId($hashData["USER_ID"])
->setHitAuthId($hashData["ID"])
;
$this->Authorize($context, $remember);
if ($delete)
{
UserHitAuthTable::delete($hashData['ID']);
}
else
{
UserHitAuthTable::update($hashData['ID'], ['TIMESTAMP_X' => new MainTypeDateTime()]);
}
return true;
}
}
return false;
}