Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
agreementlink.php
1
<?php
2
10
namespace
Bitrix\Main\UserConsent
;
11
12
use
Bitrix\Main\Error
;
13
use
Bitrix\Main\Localization\Loc
;
14
use
Bitrix\Main\Security\Sign\Signer
;
15
use
Bitrix\Main\Web\Uri
;
16
use
Bitrix\Main\Web\Json
;
17
18
Loc::loadLanguageFile
(__FILE__);
19
24
class
AgreementLink
25
{
26
const
SIGN_SALT
=
'user_consent'
;
27
29
protected
static
$errors
= [];
30
39
public
static
function
getUri
($agreementId, array $replace = [], $baseUri =
''
)
40
{
41
self::clearErrors
();
42
43
$agreement =
new
Agreement
($agreementId, $replace);
44
$signer =
new
Signer
();
45
$data = [
46
'id'
=> $agreement->getId(),
47
'replace'
=> $replace,
48
];
49
$data = Json::encode($data);
50
$parameters = [
51
'data'
=> base64_encode($data),
52
'sec'
=> base64_encode($signer->getSignature($data, self::SIGN_SALT)),
53
];
54
$uri =
new
Uri
($baseUri);
55
$uri->addParams($parameters);
56
57
return
$uri->getLocator();
58
}
59
66
public
static
function
getAgreementFromUriParameters
(array $parameters = [])
67
{
68
self::clearErrors
();
69
70
$data = $parameters[
'data'
];
71
$sec = $parameters[
'sec'
];
72
if
(!$data || !$sec || !is_string($data) || !is_string($sec))
73
{
74
self::$errors[] =
new
Error
(
'Parameters not found'
, 1);
75
return
null
;
76
}
77
78
$data = base64_decode($data);
79
$sec = base64_decode($sec);
80
if
(!$data || !$sec)
81
{
82
self::$errors[] =
new
Error
(
'Can not decode parameters'
, 2);
83
return
null
;
84
}
85
86
try
87
{
88
$signer =
new
Signer
();
89
if
(!$signer->validate($data, $sec, self::SIGN_SALT))
90
{
91
self::$errors[] =
new
Error
(
'Parameters signature is not valid'
, 3);
92
return
null
;
93
}
94
}
95
catch
(\Exception $exception)
96
{
97
self::$errors[] =
new
Error
(
'Parameters signature error: '
. $exception->getMessage(), 7);
98
return
null
;
99
}
100
101
try
102
{
103
$data = Json::decode($data);
104
}
105
catch
(\Exception)
106
{
107
$data =
null
;
108
}
109
if
(!$data || !isset($data[
'id'
]) || !isset($data[
'replace'
]))
110
{
111
self::$errors[] =
new
Error
(
'Decode data parameters failed'
, 6);
112
return
null
;
113
}
114
115
$agreement =
new
Agreement
($data[
'id'
], $data[
'replace'
]);
116
if
(!$agreement->isExist())
117
{
118
self::$errors[] =
new
Error
(
'Agreement is not exist'
, 4);
119
return
null
;
120
}
121
if
(!$agreement->isActive())
122
{
123
self::$errors[] =
new
Error
(
'Agreement is not active'
, 5);
124
return
null
;
125
}
126
127
return
$agreement;
128
}
129
130
protected
static
function
clearErrors
()
131
{
132
self::$errors = [];
133
}
134
140
public
static
function
getErrors
()
141
{
142
return
self::$errors
;
143
}
144
}
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadLanguageFile
static loadLanguageFile($file, $language=null, $normalize=true)
Definition
loc.php:224
Bitrix\Main\Security\Sign\Signer
Definition
signer.php:13
Bitrix\Main\UserConsent\Agreement
Definition
agreement.php:25
Bitrix\Main\UserConsent\AgreementLink
Definition
agreementlink.php:25
Bitrix\Main\UserConsent\AgreementLink\getAgreementFromUriParameters
static getAgreementFromUriParameters(array $parameters=[])
Definition
agreementlink.php:66
Bitrix\Main\UserConsent\AgreementLink\getErrors
static getErrors()
Definition
agreementlink.php:140
Bitrix\Main\UserConsent\AgreementLink\getUri
static getUri($agreementId, array $replace=[], $baseUri='')
Definition
agreementlink.php:39
Bitrix\Main\UserConsent\AgreementLink\SIGN_SALT
const SIGN_SALT
Definition
agreementlink.php:26
Bitrix\Main\UserConsent\AgreementLink\$errors
static $errors
Definition
agreementlink.php:29
Bitrix\Main\UserConsent\AgreementLink\clearErrors
static clearErrors()
Definition
agreementlink.php:130
Bitrix\Main\Web\Json
Definition
json.php:11
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\Main\UserConsent
Definition
agreement.php:8
modules
main
lib
userconsent
agreementlink.php
Создано системой
1.10.0