1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
agreementlink.php
См. документацию.
1
<?php
2
9
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
Определения
error.php:15
Bitrix\Main\Security\Sign\Signer
Определения
signer.php:14
Bitrix\Main\UserConsent\Agreement
Определения
agreement.php:25
Bitrix\Main\UserConsent\AgreementLink
Определения
agreementlink.php:25
Bitrix\Main\UserConsent\AgreementLink\getAgreementFromUriParameters
static getAgreementFromUriParameters(array $parameters=[])
Определения
agreementlink.php:66
Bitrix\Main\UserConsent\AgreementLink\getErrors
static getErrors()
Определения
agreementlink.php:140
Bitrix\Main\UserConsent\AgreementLink\getUri
static getUri($agreementId, array $replace=[], $baseUri='')
Определения
agreementlink.php:39
Bitrix\Main\UserConsent\AgreementLink\SIGN_SALT
const SIGN_SALT
Определения
agreementlink.php:26
Bitrix\Main\UserConsent\AgreementLink\$errors
static $errors
Определения
agreementlink.php:29
Bitrix\Main\UserConsent\AgreementLink\clearErrors
static clearErrors()
Определения
agreementlink.php:130
Bitrix\Main\Web\Uri
Определения
uri.php:17
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
bitrix
modules
main
lib
userconsent
agreementlink.php
Создано системой
1.14.0