1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace Spryker\Zed\Customer; |
||
9 | |||
10 | use Generated\Shared\Transfer\SequenceNumberSettingsTransfer; |
||
11 | use Spryker\Shared\Customer\CustomerConstants; |
||
12 | use Spryker\Shared\Kernel\Store; |
||
13 | use Spryker\Shared\SequenceNumber\SequenceNumberConstants; |
||
14 | use Spryker\Zed\Kernel\AbstractBundleConfig; |
||
15 | |||
16 | /** |
||
17 | * @method \Spryker\Shared\Customer\CustomerConfig getSharedConfig() |
||
18 | */ |
||
19 | class CustomerConfig extends AbstractBundleConfig |
||
20 | { |
||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | public const ERROR_CODE_CUSTOMER_ALREADY_REGISTERED = 4001; |
||
25 | |||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | public const ERROR_CODE_CUSTOMER_INVALID_EMAIL = 4002; |
||
30 | |||
31 | /** |
||
32 | * @uses \Spryker\Zed\Customer\Communication\Plugin\Mail\CustomerRegistrationMailTypePlugin::MAIL_TYPE |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | public const CUSTOMER_REGISTRATION_MAIL_TYPE = 'customer registration mail'; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | public const CUSTOMER_REGISTRATION_WITH_CONFIRMATION_MAIL_TYPE = 'customer registration confirmation mail'; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | public const GLOSSARY_KEY_CONFIRM_EMAIL_LINK_INVALID_OR_USED = 'customer.error.confirm_email_link.invalid_or_used'; |
||
47 | |||
48 | /** |
||
49 | * Specification: |
||
50 | * - Regular expression to validate Customer First Name field. |
||
51 | * |
||
52 | * @api |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | public const PATTERN_FIRST_NAME = '/^[^:\/<>]+$/'; |
||
57 | |||
58 | /** |
||
59 | * Specification: |
||
60 | * - Regular expression to validate Customer Last Name field. |
||
61 | * |
||
62 | * @api |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | public const PATTERN_LAST_NAME = '/^[^:\/<>]+$/'; |
||
67 | |||
68 | /** |
||
69 | * @var int |
||
70 | */ |
||
71 | protected const MIN_LENGTH_CUSTOMER_PASSWORD = 1; |
||
72 | |||
73 | /** |
||
74 | * @uses \Symfony\Component\Security\Core\Encoder\NativePasswordEncoder::MAX_PASSWORD_LENGTH |
||
75 | * |
||
76 | * @var int |
||
77 | */ |
||
78 | protected const MAX_LENGTH_CUSTOMER_PASSWORD = 72; |
||
79 | |||
80 | /** |
||
81 | * @var int |
||
82 | */ |
||
83 | protected const ERROR_CODE_CUSTOMER_INVALID_SALUTATION = 4003; |
||
84 | |||
85 | /** |
||
86 | * @var string |
||
87 | */ |
||
88 | protected const REGISTRATION_CONFIRMATION_TOKEN_URL_FALLBACK = '/register/confirm?token=%s&_store=%s'; |
||
89 | |||
90 | /** |
||
91 | * @var string |
||
92 | */ |
||
93 | protected const REGISTRATION_CONFIRMATION_TOKEN_URL_FALLBACK_WITHOUT_STORE = '/register/confirm?token=%s'; |
||
94 | |||
95 | /** |
||
96 | * @var string |
||
97 | */ |
||
98 | protected const PASSWORD_RESTORE_TOKEN_URL = '%s/password/restore?token=%s&_store=%s'; |
||
99 | |||
100 | /** |
||
101 | * @var string |
||
102 | */ |
||
103 | protected const PASSWORD_RESTORE_TOKEN_URL_WITHOUT_STORE = '%s/password/restore?token=%s'; |
||
104 | |||
105 | /** |
||
106 | * @var string |
||
107 | */ |
||
108 | protected const CUSTOMER_PASSWORD_EXPIRATION_PERIOD = '+2 hours'; |
||
109 | |||
110 | /** |
||
111 | * @var bool |
||
112 | */ |
||
113 | protected const PASSWORD_RESET_EXPIRATION_IS_ENABLED = false; |
||
114 | |||
115 | /** |
||
116 | * @api |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getHostYves() |
||
121 | { |
||
122 | return $this->get(CustomerConstants::BASE_URL_YVES); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Specification: |
||
127 | * - Toggles the password reset expiration. |
||
128 | * - It is enabled by default. |
||
129 | * |
||
130 | * @api |
||
131 | * |
||
132 | * @return bool |
||
133 | */ |
||
134 | public function isCustomerPasswordResetExpirationEnabled(): bool |
||
135 | { |
||
136 | return static::PASSWORD_RESET_EXPIRATION_IS_ENABLED; |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Specification: |
||
141 | * - Returns a time string that must be compatible with https://www.php.net/manual/en/datetime.modify.php that is used to check if the password reset has been expired. |
||
142 | * - The default is 2h hours. |
||
143 | * |
||
144 | * @api |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function getCustomerPasswordResetExpirationPeriod(): string |
||
149 | { |
||
150 | return static::CUSTOMER_PASSWORD_EXPIRATION_PERIOD; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * @api |
||
155 | * |
||
156 | * @param string $token |
||
157 | * @param string|null $storeName |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getCustomerPasswordRestoreTokenUrl($token, ?string $storeName = null): string |
||
162 | { |
||
163 | if ($storeName === null) { |
||
164 | return sprintf(static::PASSWORD_RESTORE_TOKEN_URL_WITHOUT_STORE, $this->getHostYves(), $token); |
||
165 | } |
||
166 | |||
167 | return sprintf(static::PASSWORD_RESTORE_TOKEN_URL, $this->getHostYves(), $token, $storeName); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Specification: |
||
172 | * - Provides a registration confirmation token url. |
||
173 | * |
||
174 | * @api |
||
175 | * |
||
176 | * @param string $token |
||
177 | * @param string|null $storeName |
||
178 | * |
||
179 | * @return string |
||
180 | */ |
||
181 | public function getRegisterConfirmTokenUrl($token, ?string $storeName = null): string |
||
182 | { |
||
183 | if ($storeName === null) { |
||
184 | $fallback = $this->getHostYves() . static::REGISTRATION_CONFIRMATION_TOKEN_URL_FALLBACK_WITHOUT_STORE; |
||
185 | |||
186 | return sprintf($this->get(CustomerConstants::REGISTRATION_CONFIRMATION_TOKEN_URL, $fallback), $token); |
||
187 | } |
||
188 | |||
189 | $fallback = $this->getHostYves() . static::REGISTRATION_CONFIRMATION_TOKEN_URL_FALLBACK; |
||
190 | |||
191 | return sprintf($this->get(CustomerConstants::REGISTRATION_CONFIRMATION_TOKEN_URL, $fallback), $token, $storeName); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * @api |
||
196 | * |
||
197 | * @param string|null $sequenceNumberPrefix |
||
198 | * |
||
199 | * @return \Generated\Shared\Transfer\SequenceNumberSettingsTransfer |
||
200 | */ |
||
201 | public function getCustomerReferenceDefaults(?string $sequenceNumberPrefix = null) |
||
202 | { |
||
203 | if (!$sequenceNumberPrefix) { |
||
204 | $storeName = $this->getStoreName(); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
205 | } |
||
206 | |||
207 | $sequenceNumberSettingsTransfer = new SequenceNumberSettingsTransfer(); |
||
208 | |||
209 | $sequenceNumberSettingsTransfer->setName(CustomerConstants::NAME_CUSTOMER_REFERENCE); |
||
210 | |||
211 | $sequenceNumberPrefixParts = []; |
||
212 | $sequenceNumberPrefixParts[] = $sequenceNumberPrefix; |
||
213 | $sequenceNumberPrefixParts[] = $this->get(SequenceNumberConstants::ENVIRONMENT_PREFIX, ''); |
||
214 | $prefix = implode($this->getUniqueIdentifierSeparator(), $sequenceNumberPrefixParts) . $this->getUniqueIdentifierSeparator(); |
||
215 | $sequenceNumberSettingsTransfer->setPrefix($prefix); |
||
216 | |||
217 | return $sequenceNumberSettingsTransfer; |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * Specification: |
||
222 | * - Provides a prefix used during customer reference generation. |
||
223 | * |
||
224 | * @api |
||
225 | * |
||
226 | * @return string|null |
||
227 | */ |
||
228 | public function getCustomerSequenceNumberPrefix(): ?string |
||
229 | { |
||
230 | return null; |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * Specification: |
||
235 | * - Provides regular expression for character set password validation. |
||
236 | * |
||
237 | * @api |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | public function getCustomerPasswordCharacterSet(): string |
||
242 | { |
||
243 | return '/^.*$/'; |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * This method provides list of URLs to render blocks inside customer detail page. |
||
248 | * URL defines path to external bundle controller. For example: /sales/customer/customer-orders would call sales bundle, customer controller, customerOrders action. |
||
249 | * |
||
250 | * example: |
||
251 | * [ |
||
252 | * 'sales' => '/sales/customer/customer-orders', |
||
253 | * ] |
||
254 | * |
||
255 | * @api |
||
256 | * |
||
257 | * @return array<string> |
||
258 | */ |
||
259 | public function getCustomerDetailExternalBlocksUrls() |
||
260 | { |
||
261 | return []; |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * @api |
||
266 | * |
||
267 | * @return int |
||
268 | */ |
||
269 | public function getCustomerPasswordMinLength(): int |
||
270 | { |
||
271 | return static::MIN_LENGTH_CUSTOMER_PASSWORD; |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * @api |
||
276 | * |
||
277 | * @return int |
||
278 | */ |
||
279 | public function getCustomerPasswordMaxLength(): int |
||
280 | { |
||
281 | return static::MAX_LENGTH_CUSTOMER_PASSWORD; |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * Specification: |
||
286 | * - Provides a list of strings that will be accepted as a password for customer bypassing any policy validations. |
||
287 | * |
||
288 | * @api |
||
289 | * |
||
290 | * @return array<string> |
||
291 | */ |
||
292 | public function getCustomerPasswordAllowList(): array |
||
293 | { |
||
294 | return []; |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * Specification: |
||
299 | * - A common list of insecure, invalid passwords. |
||
300 | * |
||
301 | * @api |
||
302 | * |
||
303 | * @return array<string> |
||
304 | */ |
||
305 | public function getCustomerPasswordDenyList(): array |
||
306 | { |
||
307 | return []; |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * Specification: |
||
312 | * - Provides a limit for character repeating if defined. |
||
313 | * |
||
314 | * Example |
||
315 | * - Limit=4, forbids to use "aaaa" in password, but allows "aaa" |
||
316 | * |
||
317 | * @api |
||
318 | * |
||
319 | * @return int|null |
||
320 | */ |
||
321 | public function getCustomerPasswordSequenceLimit(): ?int |
||
322 | { |
||
323 | return null; |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * Specification: |
||
328 | * - Enables password check for CustomerFacade::restorePassword() method. |
||
329 | * |
||
330 | * @api |
||
331 | * |
||
332 | * @deprecated Method is introduced for BC reasons only and will be removed without replacement |
||
333 | * |
||
334 | * @return bool |
||
335 | */ |
||
336 | public function isRestorePasswordValidationEnabled(): bool |
||
337 | { |
||
338 | return false; |
||
339 | } |
||
340 | |||
341 | /** |
||
342 | * @api |
||
343 | * |
||
344 | * @uses \Spryker\Shared\Customer\CustomerConfig::isDoubleOptInEnabled() |
||
345 | * |
||
346 | * @return bool |
||
347 | */ |
||
348 | public function isDoubleOptInEnabled(): bool |
||
349 | { |
||
350 | return $this->getSharedConfig()->isDoubleOptInEnabled(); |
||
351 | } |
||
352 | |||
353 | /** |
||
354 | * @api |
||
355 | * |
||
356 | * @return int |
||
357 | */ |
||
358 | public function getCustomerInvalidSalutationErrorCode(): int |
||
359 | { |
||
360 | return static::ERROR_CODE_CUSTOMER_INVALID_SALUTATION; |
||
361 | } |
||
362 | |||
363 | /** |
||
364 | * @return string |
||
365 | */ |
||
366 | protected function getUniqueIdentifierSeparator() |
||
367 | { |
||
368 | return '-'; |
||
369 | } |
||
370 | |||
371 | /** |
||
372 | * @deprecated Will be removed in the next major without replacement. |
||
373 | * |
||
374 | * @return string |
||
375 | */ |
||
376 | protected function getStoreName(): string |
||
377 | { |
||
378 | return Store::getInstance()->getStoreName(); |
||
379 | } |
||
380 | } |
||
381 |