1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
PasswordService.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
11use Bitrix\Rest\Enum;
14use Bitrix\Rest\Dto;
18
20{
21 private const BASE_CACHE_DIR = 'rest/apauth/password';
22
23 public function __construct(
24 private ?Contract\Repository\APAuth\PasswordRepository $passwordRepository = null,
25 private ?Contract\Service\APAuth\PermissionService $permissionService = null,
26 )
27 {
28 $this->passwordRepository ??= new PasswordRepository();
29 $this->permissionService ??= ServiceContainer::getInstance()->getAPAuthPermissionService();
30 }
31
33 {
34 return $this->passwordRepository->getByType(Enum\APAuth\PasswordType::System);
35 }
36
37 public function isSystemPasswordById(int $id): bool
38 {
39 $cache = Application::getInstance()->getCache();
40
41 if (
42 $cache->initCache(
43 86400 * 7,
44 'is_system_password',
45 self::BASE_CACHE_DIR . '/' . $id))
46 {
47 $isSystemPassword = $cache->getVars();
48 }
49 else
50 {
51 $isSystemPassword = $this->passwordRepository->getById($id)?->getType() === Enum\APAuth\PasswordType::System;
52 $cache->startDataCache();
53 $cache->endDataCache($isSystemPassword);
54 }
55
56 return $isSystemPassword;
57 }
58
59 public function getPasswordById(int $id): ?Password
60 {
61 return $this->passwordRepository->getById($id);
62 }
63
64 public function deleteById(int $id): bool
65 {
66 return $this->passwordRepository->deleteById($id);
67 }
68
69 public function create(Dto\APAuth\CreatePasswordDto $createPasswordDto): ?Password
70 {
71 $password = new Password(
72 id: 0,
73 passwordString: Random::getString(16),
74 userId: $createPasswordDto->getUserId(),
75 type: $createPasswordDto->getType(),
76 title: $createPasswordDto->getTitle(),
77 comment: $createPasswordDto->getComment(),
78 createdAt: new DateTime(),
79 );
80
81 try
82 {
83 $password = $this->passwordRepository->create($password);
84
85 foreach ($createPasswordDto->getPermissions() as $permissionCode)
86 {
87 $createPermissionDto = new Dto\APAuth\CreatePermissionDto(
88 permissionCode: $permissionCode,
89 passwordId: $password->getId()
90 );
91 $this->permissionService->create($createPermissionDto);
92 }
93
94 return $password;
95 }
97 {
98 return null;
99 }
100 }
101
102 public function clearCacheById(int $id): void
103 {
104 Application::getInstance()->getCache()->clean(self::BASE_CACHE_DIR . '/' . $id);
105 }
106}
__construct(private ?Contract\Repository\APAuth\PasswordRepository $passwordRepository=null, private ?Contract\Service\APAuth\PermissionService $permissionService=null,)
Определения PasswordService.php:23
create(Dto\APAuth\CreatePasswordDto $createPasswordDto)
Определения PasswordService.php:69
$password
Определения mysql_to_pgsql.php:34
<? endif;?> window document title
Определения prolog_main_admin.php:76