1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AuthorizationRepository.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
9use Bitrix\Rest\Internal\Model;
10
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 {
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
Определения actionsdefinitions.php:38
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
saveAuthorization(int $userId, int $applicationId, Main\Type\DateTime $time)
Определения AuthorizationRepository.php:25
const SEVERITY_SECURITY
Определения event_log.php:22
static Log($SEVERITY, $AUDIT_TYPE_ID, $MODULE_ID, $ITEM_ID, $DESCRIPTION=false, $SITE_ID=false)
Определения event_log.php:32
Определения collection.php:2
$time
Определения payment.php:61