1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
PasswordService.php
См. документацию.
1
<?php
2
3
declare(strict_types=1);
4
5
namespace
Bitrix\Rest\Service\APAuth
;
6
7
use
Bitrix\Main\Application
;
8
use
Bitrix\Main\Security\Random
;
9
use
Bitrix\Main\Type\DateTime
;
10
use
Bitrix\Rest\Entity\APAuth\Password
;
11
use Bitrix\Rest\Enum;
12
use
Bitrix\Rest\Entity\Collection\APAuth\PasswordCollection
;
13
use
Bitrix\Rest\Contract
;
14
use Bitrix\Rest\Dto;
15
use
Bitrix\Rest\Repository\APAuth\PasswordRepository
;
16
use
Bitrix\Rest\Repository\Exception\CreationFailedException
;
17
use
Bitrix\Rest\Service\ServiceContainer
;
18
19
class
PasswordService
implements
Contract\Service\APAuth\PasswordService
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
32
public
function
getSystemPasswordCollection
():
PasswordCollection
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
}
96
catch
(
CreationFailedException
)
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
}
Bitrix\Main\Application
Определения
application.php:30
Bitrix\Main\Security\Random
Определения
random.php:6
Bitrix\Main\Type\DateTime
Определения
datetime.php:9
Bitrix\Rest\Dto\APAuth\CreatePermissionDto
Определения
CreatePermissionDto.php:8
Bitrix\Rest\Entity\APAuth\Password
Определения
Password.php:11
Bitrix\Rest\Entity\Collection\APAuth\PasswordCollection
Определения
PasswordCollection.php:14
Bitrix\Rest\Repository\APAuth\PasswordRepository
Определения
PasswordRepository.php:18
Bitrix\Rest\Repository\Exception\CreationFailedException
Определения
CreationFailedException.php:8
Bitrix\Rest\Service\APAuth\PasswordService
Определения
PasswordService.php:20
Bitrix\Rest\Service\APAuth\PasswordService\getSystemPasswordCollection
getSystemPasswordCollection()
Определения
PasswordService.php:32
Bitrix\Rest\Service\APAuth\PasswordService\isSystemPasswordById
isSystemPasswordById(int $id)
Определения
PasswordService.php:37
Bitrix\Rest\Service\APAuth\PasswordService\clearCacheById
clearCacheById(int $id)
Определения
PasswordService.php:102
Bitrix\Rest\Service\APAuth\PasswordService\__construct
__construct(private ?Contract\Repository\APAuth\PasswordRepository $passwordRepository=null, private ?Contract\Service\APAuth\PermissionService $permissionService=null,)
Определения
PasswordService.php:23
Bitrix\Rest\Service\APAuth\PasswordService\deleteById
deleteById(int $id)
Определения
PasswordService.php:64
Bitrix\Rest\Service\APAuth\PasswordService\create
create(Dto\APAuth\CreatePasswordDto $createPasswordDto)
Определения
PasswordService.php:69
Bitrix\Rest\Service\APAuth\PasswordService\getPasswordById
getPasswordById(int $id)
Определения
PasswordService.php:59
Bitrix\Rest\Service\APAuth\PermissionService
Определения
PermissionService.php:14
Bitrix\Rest\Service\ServiceContainer
Определения
ServiceContainer.php:16
Bitrix\Rest\Service\ServiceContainer\getInstance
static getInstance()
Определения
ServiceContainer.php:30
Bitrix\Rest\Contract\Service\APAuth\PasswordService
Определения
PasswordService.php:12
Bitrix\Main\Type\Contract
Определения
arrayable.php:3
Bitrix\Main\$password
$password
Определения
mysql_to_pgsql.php:34
Bitrix\Rest\Contract\Repository
Bitrix\Rest\Contract\Service
Bitrix\Rest\Contract
Определения
OptionContract.php:3
Bitrix\Rest\Dto\APAuth
Определения
CreatePasswordDto.php:5
Bitrix\Rest\Service\APAuth
Определения
PasswordService.php:5
title
<? endif;?> window document title
Определения
prolog_main_admin.php:76
bitrix
modules
rest
lib
Service
APAuth
PasswordService.php
Создано системой
1.14.0