1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
AuthorizationRepository.php
См. документацию.
1
<?php
2
3
declare(strict_types=1);
4
5
namespace
Bitrix\Rest\Internal\Repository\Auth
;
6
7
use
Bitrix\Main
;
8
use
Bitrix\Main\Application
;
9
use Bitrix\Rest\Internal\Model;
10
11
class
AuthorizationRepository
12
{
13
protected
const
LOCK_NAME
=
'rest_auth_log'
;
14
protected
const
LOCK_LIMIT
= 0;
15
16
private
const
CACHE_ID =
'rest_auth_log'
;
17
private
const
CACHE_TTL = 3600;
18
private
Main\Data\ManagedCache
$managedCache;
19
20
public
function
__construct
()
21
{
22
$this->managedCache = Application::getInstance()->getManagedCache();
23
}
24
25
public
function
saveAuthorization
(
int
$userId
,
int
$applicationId,
Main
\
Type
\
DateTime
$time
): void
26
{
27
$cacheId = $this->getCacheId(
$userId
, $applicationId,
$time
);
28
$cacheIsSet = $this->managedCache->read(static::CACHE_TTL, $cacheId) ===
true
;
29
30
if
($cacheIsSet)
31
{
32
return
;
33
}
34
35
$this->managedCache->setImmediate($cacheId,
'Y'
);
36
37
if
($this->lock(
$userId
))
38
{
39
\CEventLog::Log
(
40
\
CEventLog::SEVERITY_SECURITY
,
41
'USER_AUTHORIZE'
,
42
'rest'
,
43
$userId
,
44
json_encode([
45
'userId'
=>
$userId
,
46
'applicationId'
=> $applicationId,
47
'timePeriod'
=>
$time
->format(
'Y-m-d H'
),
48
])
49
);
50
51
$this->unlock(
$userId
);
52
}
53
}
54
55
private
function
lock(
int
$userId
): bool
56
{
57
$connection
= Application::getConnection();
58
59
return
$connection
->lock(self::LOCK_NAME .
'_ '
.
$userId
, self::LOCK_LIMIT);
60
}
61
62
private
function
unlock(
int
$userId
): void
63
{
64
$connection
= Application::getConnection();
65
66
$connection
->unlock(self::LOCK_NAME .
'_ '
.
$userId
);
67
}
68
69
private
function
getCacheId(
int
$userId
,
int
$applicationId,
Main
\
Type
\
DateTime
$time
): string
70
{
71
return
static::CACHE_ID .
'_'
.
$userId
.
'_'
. $applicationId .
'_'
.
$time
->format(
'Y-m-d H'
);
72
}
73
}
$connection
$connection
Определения
actionsdefinitions.php:38
$userId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения
check_mail.php:18
Bitrix\Main\Application
Определения
application.php:30
Bitrix\Main\Data\ManagedCache
Определения
managedcache.php:15
Bitrix\Main\Type\DateTime
Определения
datetime.php:9
Bitrix\Rest\Internal\Repository\Auth\AuthorizationRepository
Определения
AuthorizationRepository.php:12
Bitrix\Rest\Internal\Repository\Auth\AuthorizationRepository\__construct
__construct()
Определения
AuthorizationRepository.php:20
Bitrix\Rest\Internal\Repository\Auth\AuthorizationRepository\LOCK_LIMIT
const LOCK_LIMIT
Определения
AuthorizationRepository.php:14
Bitrix\Rest\Internal\Repository\Auth\AuthorizationRepository\saveAuthorization
saveAuthorization(int $userId, int $applicationId, Main\Type\DateTime $time)
Определения
AuthorizationRepository.php:25
Bitrix\Rest\Internal\Repository\Auth\AuthorizationRepository\LOCK_NAME
const LOCK_NAME
Определения
AuthorizationRepository.php:13
CEventLog\SEVERITY_SECURITY
const SEVERITY_SECURITY
Определения
event_log.php:22
CEventLog\Log
static Log($SEVERITY, $AUDIT_TYPE_ID, $MODULE_ID, $ITEM_ID, $DESCRIPTION=false, $SITE_ID=false)
Определения
event_log.php:32
Bitrix\Main\Type
Определения
collection.php:2
Bitrix\Main
Bitrix\Rest\Internal\Repository\Auth
Определения
AuthorizationRepository.php:5
$time
$time
Определения
payment.php:61
bitrix
modules
rest
lib
Internal
Repository
Auth
AuthorizationRepository.php
Создано системой
1.14.0