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 (
@@ -906,6 +925,8 @@ public function getDefaultShippingAddress($customerId)
906
925
* @param string $redirectUrl
907
926
* @param array $extensions
908
927
* @return void
928
+ * @throws LocalizedException
929
+ * @throws NoSuchEntityException
909
930
*/
910
931
protected function sendEmailConfirmation (CustomerInterface $ customer , $ redirectUrl , $ extensions = [])
911
932
{
@@ -967,7 +988,10 @@ public function changePasswordById($customerId, $currentPassword, $newPassword)
967
988
* @param string $newPassword
968
989
* @return bool true on success
969
990
* @throws InputException
991
+ * @throws InputMismatchException
970
992
* @throws InvalidEmailOrPasswordException
993
+ * @throws LocalizedException
994
+ * @throws NoSuchEntityException
971
995
* @throws UserLockedException
972
996
*/
973
997
private function changePasswordForCustomer ($ customer , $ currentPassword , $ newPassword )
@@ -1076,10 +1100,11 @@ public function isCustomerInStore($customerWebsiteId, $storeId)
1076
1100
* @param int $customerId
1077
1101
* @param string $resetPasswordLinkToken
1078
1102
* @return bool
1079
- * @throws \Magento\Framework\Exception\State\InputMismatchException If token is mismatched
1080
- * @throws \Magento\Framework\Exception\State\ExpiredException If token is expired
1081
- * @throws \Magento\Framework\Exception\InputException If token or customer id is invalid
1082
- * @throws \Magento\Framework\Exception\NoSuchEntityException If customer doesn't exist
1103
+ * @throws ExpiredException
1104
+ * @throws InputException
1105
+ * @throws InputMismatchException
1106
+ * @throws LocalizedException
1107
+ * @throws NoSuchEntityException
1083
1108
*/
1084
1109
private function validateResetPasswordToken ($ customerId , $ resetPasswordLinkToken )
1085
1110
{
@@ -1169,6 +1194,8 @@ protected function sendNewAccountEmail(
1169
1194
*
1170
1195
* @param CustomerInterface $customer
1171
1196
* @return $this
1197
+ * @throws LocalizedException
1198
+ * @throws NoSuchEntityException
1172
1199
* @deprecated 100.1.0
1173
1200
*/
1174
1201
protected function sendPasswordResetNotificationEmail ($ customer )
@@ -1182,6 +1209,7 @@ protected function sendPasswordResetNotificationEmail($customer)
1182
1209
* @param CustomerInterface $customer
1183
1210
* @param int|string|null $defaultStoreId
1184
1211
* @return int
1212
+ * @throws LocalizedException
1185
1213
* @deprecated 100.1.0
1186
1214
*/
1187
1215
protected function getWebsiteStoreId ($ customer , $ defaultStoreId = null )
@@ -1195,6 +1223,8 @@ protected function getWebsiteStoreId($customer, $defaultStoreId = null)
1195
1223
}
1196
1224
1197
1225
/**
1226
+ * Get email template types
1227
+ *
1198
1228
* @return array
1199
1229
* @deprecated 100.1.0
1200
1230
*/
@@ -1228,6 +1258,7 @@ protected function getTemplateTypes()
1228
1258
* @param int|null $storeId
1229
1259
* @param string $email
1230
1260
* @return $this
1261
+ * @throws MailException
1231
1262
* @deprecated 100.1.0
1232
1263
*/
1233
1264
protected function sendEmailTemplate (
@@ -1334,6 +1365,9 @@ public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
1334
1365
* @param string $passwordLinkToken
1335
1366
* @return bool
1336
1367
* @throws InputException
1368
+ * @throws InputMismatchException
1369
+ * @throws LocalizedException
1370
+ * @throws NoSuchEntityException
1337
1371
*/
1338
1372
public function changeResetPasswordLinkToken ($ customer , $ passwordLinkToken )
1339
1373
{
@@ -1361,6 +1395,8 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
1361
1395
*
1362
1396
* @param CustomerInterface $customer
1363
1397
* @return $this
1398
+ * @throws LocalizedException
1399
+ * @throws NoSuchEntityException
1364
1400
* @deprecated 100.1.0
1365
1401
*/
1366
1402
public function sendPasswordReminderEmail ($ customer )
@@ -1388,6 +1424,8 @@ public function sendPasswordReminderEmail($customer)
1388
1424
*
1389
1425
* @param CustomerInterface $customer
1390
1426
* @return $this
1427
+ * @throws LocalizedException
1428
+ * @throws NoSuchEntityException
1391
1429
* @deprecated 100.1.0
1392
1430
*/
1393
1431
public function sendPasswordResetConfirmationEmail ($ customer )
@@ -1432,6 +1470,7 @@ protected function getAddressById(CustomerInterface $customer, $addressId)
1432
1470
*
1433
1471
* @param CustomerInterface $customer
1434
1472
* @return Data\CustomerSecure
1473
+ * @throws NoSuchEntityException
1435
1474
* @deprecated 100.1.0
1436
1475
*/
1437
1476
protected function getFullCustomerObject ($ customer )
@@ -1457,6 +1496,20 @@ public function getPasswordHash($password)
1457
1496
return $ this ->encryptor ->getHash ($ password );
1458
1497
}
1459
1498
1499
+ /**
1500
+ * Disable Customer Address Validation
1501
+ *
1502
+ * @param CustomerInterface $customer
1503
+ * @throws NoSuchEntityException
1504
+ */
1505
+ private function disableAddressValidation ($ customer )
1506
+ {
1507
+ foreach ($ customer ->getAddresses () as $ address ) {
1508
+ $ addressModel = $ this ->addressRegistry ->retrieve ($ address ->getId ());
1509
+ $ addressModel ->setShouldIgnoreValidation (true );
1510
+ }
1511
+ }
1512
+
1460
1513
/**
1461
1514
* Get email notification
1462
1515
*
0 commit comments