17
17
use Magento \Customer \Model \Customer as CustomerModel ;
18
18
use Magento \Customer \Model \Customer \CredentialsValidator ;
19
19
use Magento \Customer \Model \Metadata \Validator ;
20
+ use Magento \Customer \Model \ResourceModel \Visitor \CollectionFactory ;
20
21
use Magento \Eav \Model \Validator \Attribute \Backend ;
21
22
use Magento \Framework \Api \ExtensibleDataObjectConverter ;
22
23
use Magento \Framework \Api \SearchCriteriaBuilder ;
44
45
use Magento \Framework \Phrase ;
45
46
use Magento \Framework \Reflection \DataObjectProcessor ;
46
47
use Magento \Framework \Registry ;
48
+ use Magento \Framework \Session \SaveHandlerInterface ;
49
+ use Magento \Framework \Session \SessionManagerInterface ;
47
50
use Magento \Framework \Stdlib \DateTime ;
48
51
use Magento \Framework \Stdlib \StringUtils as StringHelper ;
49
52
use Magento \Store \Model \ScopeInterface ;
50
53
use Magento \Store \Model \StoreManagerInterface ;
51
54
use Psr \Log \LoggerInterface as PsrLogger ;
52
- use Magento \Framework \Session \SessionManagerInterface ;
53
- use Magento \Framework \Session \SaveHandlerInterface ;
54
- use Magento \Customer \Model \ResourceModel \Visitor \CollectionFactory ;
55
55
56
56
/**
57
57
* Handle various customer account actions
@@ -332,6 +332,11 @@ class AccountManagement implements AccountManagementInterface
332
332
*/
333
333
private $ searchCriteriaBuilder ;
334
334
335
+ /**
336
+ * @var AddressRegistry
337
+ */
338
+ private $ addressRegistry ;
339
+
335
340
/**
336
341
* @param CustomerFactory $customerFactory
337
342
* @param ManagerInterface $eventManager
@@ -359,12 +364,13 @@ class AccountManagement implements AccountManagementInterface
359
364
* @param CredentialsValidator|null $credentialsValidator
360
365
* @param DateTimeFactory|null $dateTimeFactory
361
366
* @param AccountConfirmation|null $accountConfirmation
362
- * @param DateTimeFactory $dateTimeFactory
363
367
* @param SessionManagerInterface|null $sessionManager
364
368
* @param SaveHandlerInterface|null $saveHandler
365
369
* @param CollectionFactory|null $visitorCollectionFactory
366
370
* @param SearchCriteriaBuilder|null $searchCriteriaBuilder
371
+ * @param AddressRegistry|null $addressRegistry
367
372
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
373
+ * @SuppressWarnings(PHPMD.NPathComplexity)
368
374
*/
369
375
public function __construct (
370
376
CustomerFactory $ customerFactory ,
@@ -396,7 +402,8 @@ public function __construct(
396
402
SessionManagerInterface $ sessionManager = null ,
397
403
SaveHandlerInterface $ saveHandler = null ,
398
404
CollectionFactory $ visitorCollectionFactory = null ,
399
- SearchCriteriaBuilder $ searchCriteriaBuilder = null
405
+ SearchCriteriaBuilder $ searchCriteriaBuilder = null ,
406
+ AddressRegistry $ addressRegistry = null
400
407
) {
401
408
$ this ->customerFactory = $ customerFactory ;
402
409
$ this ->eventManager = $ eventManager ;
@@ -434,6 +441,8 @@ public function __construct(
434
441
?: ObjectManager::getInstance ()->get (CollectionFactory::class);
435
442
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder
436
443
?: ObjectManager::getInstance ()->get (SearchCriteriaBuilder::class);
444
+ $ this ->addressRegistry = $ addressRegistry
445
+ ?: ObjectManager::getInstance ()->get (AddressRegistry::class);
437
446
}
438
447
439
448
/**
@@ -499,8 +508,11 @@ public function activateById($customerId, $confirmationKey)
499
508
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
500
509
* @param string $confirmationKey
501
510
* @return \Magento\Customer\Api\Data\CustomerInterface
502
- * @throws \Magento\Framework\Exception\State\InvalidTransitionException
503
- * @throws \Magento\Framework\Exception\State\InputMismatchException
511
+ * @throws InputException
512
+ * @throws InputMismatchException
513
+ * @throws InvalidTransitionException
514
+ * @throws LocalizedException
515
+ * @throws NoSuchEntityException
504
516
*/
505
517
private function activateCustomer ($ customer , $ confirmationKey )
506
518
{
@@ -574,6 +586,9 @@ public function initiatePasswordReset($email, $template, $websiteId = null)
574
586
// load customer by email
575
587
$ customer = $ this ->customerRepository ->get ($ email , $ websiteId );
576
588
589
+ // No need to validate customer address while saving customer reset password token
590
+ $ this ->disableAddressValidation ($ customer );
591
+
577
592
$ newPasswordToken = $ this ->mathRandom ->getUniqueHash ();
578
593
$ this ->changeResetPasswordLinkToken ($ customer , $ newPasswordToken );
579
594
@@ -611,10 +626,10 @@ public function initiatePasswordReset($email, $template, $websiteId = null)
611
626
* Match a customer by their RP token.
612
627
*
613
628
* @param string $rpToken
629
+ * @return CustomerInterface
614
630
* @throws ExpiredException
631
+ * @throws LocalizedException
615
632
* @throws NoSuchEntityException
616
- *
617
- * @return CustomerInterface
618
633
*/
619
634
private function matchCustomerByRpToken (string $ rpToken ): CustomerInterface
620
635
{
@@ -657,6 +672,10 @@ public function resetPassword($email, $resetToken, $newPassword)
657
672
} else {
658
673
$ customer = $ this ->customerRepository ->get ($ email );
659
674
}
675
+
676
+ // No need to validate customer address while saving customer reset password token
677
+ $ this ->disableAddressValidation ($ customer );
678
+
660
679
//Validate Token and new password strength
661
680
$ this ->validateResetPasswordToken ($ customer ->getId (), $ resetToken );
662
681
$ this ->credentialsValidator ->checkPasswordDifferentFromEmail (
@@ -900,6 +919,8 @@ public function getDefaultShippingAddress($customerId)
900
919
* @param CustomerInterface $customer
901
920
* @param string $redirectUrl
902
921
* @return void
922
+ * @throws LocalizedException
923
+ * @throws NoSuchEntityException
903
924
*/
904
925
protected function sendEmailConfirmation (CustomerInterface $ customer , $ redirectUrl )
905
926
{
@@ -954,7 +975,10 @@ public function changePasswordById($customerId, $currentPassword, $newPassword)
954
975
* @param string $newPassword
955
976
* @return bool true on success
956
977
* @throws InputException
978
+ * @throws InputMismatchException
957
979
* @throws InvalidEmailOrPasswordException
980
+ * @throws LocalizedException
981
+ * @throws NoSuchEntityException
958
982
* @throws UserLockedException
959
983
*/
960
984
private function changePasswordForCustomer ($ customer , $ currentPassword , $ newPassword )
@@ -1063,10 +1087,11 @@ public function isCustomerInStore($customerWebsiteId, $storeId)
1063
1087
* @param int $customerId
1064
1088
* @param string $resetPasswordLinkToken
1065
1089
* @return bool
1066
- * @throws \Magento\Framework\Exception\State\InputMismatchException If token is mismatched
1067
- * @throws \Magento\Framework\Exception\State\ExpiredException If token is expired
1068
- * @throws \Magento\Framework\Exception\InputException If token or customer id is invalid
1069
- * @throws \Magento\Framework\Exception\NoSuchEntityException If customer doesn't exist
1090
+ * @throws ExpiredException
1091
+ * @throws InputException
1092
+ * @throws InputMismatchException
1093
+ * @throws LocalizedException
1094
+ * @throws NoSuchEntityException
1070
1095
*/
1071
1096
private function validateResetPasswordToken ($ customerId , $ resetPasswordLinkToken )
1072
1097
{
@@ -1156,6 +1181,8 @@ protected function sendNewAccountEmail(
1156
1181
*
1157
1182
* @param CustomerInterface $customer
1158
1183
* @return $this
1184
+ * @throws LocalizedException
1185
+ * @throws NoSuchEntityException
1159
1186
* @deprecated 100.1.0
1160
1187
*/
1161
1188
protected function sendPasswordResetNotificationEmail ($ customer )
@@ -1169,6 +1196,7 @@ protected function sendPasswordResetNotificationEmail($customer)
1169
1196
* @param CustomerInterface $customer
1170
1197
* @param int|string|null $defaultStoreId
1171
1198
* @return int
1199
+ * @throws LocalizedException
1172
1200
* @deprecated 100.1.0
1173
1201
*/
1174
1202
protected function getWebsiteStoreId ($ customer , $ defaultStoreId = null )
@@ -1182,6 +1210,8 @@ protected function getWebsiteStoreId($customer, $defaultStoreId = null)
1182
1210
}
1183
1211
1184
1212
/**
1213
+ * Get email template types
1214
+ *
1185
1215
* @return array
1186
1216
* @deprecated 100.1.0
1187
1217
*/
@@ -1215,6 +1245,7 @@ protected function getTemplateTypes()
1215
1245
* @param int|null $storeId
1216
1246
* @param string $email
1217
1247
* @return $this
1248
+ * @throws MailException
1218
1249
* @deprecated 100.1.0
1219
1250
*/
1220
1251
protected function sendEmailTemplate (
@@ -1321,6 +1352,9 @@ public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
1321
1352
* @param string $passwordLinkToken
1322
1353
* @return bool
1323
1354
* @throws InputException
1355
+ * @throws InputMismatchException
1356
+ * @throws LocalizedException
1357
+ * @throws NoSuchEntityException
1324
1358
*/
1325
1359
public function changeResetPasswordLinkToken ($ customer , $ passwordLinkToken )
1326
1360
{
@@ -1348,6 +1382,8 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
1348
1382
*
1349
1383
* @param CustomerInterface $customer
1350
1384
* @return $this
1385
+ * @throws LocalizedException
1386
+ * @throws NoSuchEntityException
1351
1387
* @deprecated 100.1.0
1352
1388
*/
1353
1389
public function sendPasswordReminderEmail ($ customer )
@@ -1375,6 +1411,8 @@ public function sendPasswordReminderEmail($customer)
1375
1411
*
1376
1412
* @param CustomerInterface $customer
1377
1413
* @return $this
1414
+ * @throws LocalizedException
1415
+ * @throws NoSuchEntityException
1378
1416
* @deprecated 100.1.0
1379
1417
*/
1380
1418
public function sendPasswordResetConfirmationEmail ($ customer )
@@ -1419,6 +1457,7 @@ protected function getAddressById(CustomerInterface $customer, $addressId)
1419
1457
*
1420
1458
* @param CustomerInterface $customer
1421
1459
* @return Data\CustomerSecure
1460
+ * @throws NoSuchEntityException
1422
1461
* @deprecated 100.1.0
1423
1462
*/
1424
1463
protected function getFullCustomerObject ($ customer )
@@ -1444,6 +1483,20 @@ public function getPasswordHash($password)
1444
1483
return $ this ->encryptor ->getHash ($ password );
1445
1484
}
1446
1485
1486
+ /**
1487
+ * Disable Customer Address Validation
1488
+ *
1489
+ * @param CustomerInterface $customer
1490
+ * @throws NoSuchEntityException
1491
+ */
1492
+ private function disableAddressValidation ($ customer )
1493
+ {
1494
+ foreach ($ customer ->getAddresses () as $ address ) {
1495
+ $ addressModel = $ this ->addressRegistry ->retrieve ($ address ->getId ());
1496
+ $ addressModel ->setShouldIgnoreValidation (true );
1497
+ }
1498
+ }
1499
+
1447
1500
/**
1448
1501
* Get email notification
1449
1502
*
0 commit comments