Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
agreementlink.php
1<?php
2
11
17
18Loc::loadLanguageFile(__FILE__);
19
25{
26 const SIGN_SALT = 'user_consent';
27
29 protected static $errors = [];
30
39 public static function getUri($agreementId, array $replace = [], $baseUri = '')
40 {
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 {
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}
static loadLanguageFile($file, $language=null, $normalize=true)
Definition loc.php:224