|
18 | 18 | use Magento\Customer\Model\Customer as CustomerModel;
|
19 | 19 | use Magento\Customer\Model\Customer\CredentialsValidator;
|
20 | 20 | use Magento\Customer\Model\Metadata\Validator;
|
| 21 | +use Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory; |
21 | 22 | use Magento\Eav\Model\Validator\Attribute\Backend;
|
22 | 23 | use Magento\Framework\Api\ExtensibleDataObjectConverter;
|
23 | 24 | use Magento\Framework\Api\SearchCriteriaBuilder;
|
|
45 | 46 | use Magento\Framework\Phrase;
|
46 | 47 | use Magento\Framework\Reflection\DataObjectProcessor;
|
47 | 48 | use Magento\Framework\Registry;
|
| 49 | +use Magento\Framework\Session\SaveHandlerInterface; |
| 50 | +use Magento\Framework\Session\SessionManagerInterface; |
48 | 51 | use Magento\Framework\Stdlib\DateTime;
|
49 | 52 | use Magento\Framework\Stdlib\StringUtils as StringHelper;
|
50 | 53 | use Magento\Store\Model\ScopeInterface;
|
51 | 54 | use Magento\Store\Model\StoreManagerInterface;
|
52 | 55 | use Psr\Log\LoggerInterface as PsrLogger;
|
53 |
| -use Magento\Framework\Session\SessionManagerInterface; |
54 |
| -use Magento\Framework\Session\SaveHandlerInterface; |
55 |
| -use Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory; |
56 | 56 |
|
57 | 57 | /**
|
58 | 58 | * Handle various customer account actions
|
@@ -333,6 +333,11 @@ class AccountManagement implements AccountManagementInterface
|
333 | 333 | */
|
334 | 334 | private $searchCriteriaBuilder;
|
335 | 335 |
|
| 336 | + /** |
| 337 | + * @var AddressRegistry |
| 338 | + */ |
| 339 | + private $addressRegistry; |
| 340 | + |
336 | 341 | /**
|
337 | 342 | * @param CustomerFactory $customerFactory
|
338 | 343 | * @param ManagerInterface $eventManager
|
@@ -364,7 +369,9 @@ class AccountManagement implements AccountManagementInterface
|
364 | 369 | * @param SaveHandlerInterface|null $saveHandler
|
365 | 370 | * @param CollectionFactory|null $visitorCollectionFactory
|
366 | 371 | * @param SearchCriteriaBuilder|null $searchCriteriaBuilder
|
| 372 | + * @param AddressRegistry|null $addressRegistry |
367 | 373 | * @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
| 374 | + * @SuppressWarnings(PHPMD.NPathComplexity) |
368 | 375 | */
|
369 | 376 | public function __construct(
|
370 | 377 | CustomerFactory $customerFactory,
|
@@ -396,7 +403,8 @@ public function __construct(
|
396 | 403 | SessionManagerInterface $sessionManager = null,
|
397 | 404 | SaveHandlerInterface $saveHandler = null,
|
398 | 405 | CollectionFactory $visitorCollectionFactory = null,
|
399 |
| - SearchCriteriaBuilder $searchCriteriaBuilder = null |
| 406 | + SearchCriteriaBuilder $searchCriteriaBuilder = null, |
| 407 | + AddressRegistry $addressRegistry = null |
400 | 408 | ) {
|
401 | 409 | $this->customerFactory = $customerFactory;
|
402 | 410 | $this->eventManager = $eventManager;
|
@@ -434,6 +442,8 @@ public function __construct(
|
434 | 442 | ?: ObjectManager::getInstance()->get(CollectionFactory::class);
|
435 | 443 | $this->searchCriteriaBuilder = $searchCriteriaBuilder
|
436 | 444 | ?: ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
|
| 445 | + $this->addressRegistry = $addressRegistry |
| 446 | + ?: ObjectManager::getInstance()->get(AddressRegistry::class); |
437 | 447 | }
|
438 | 448 |
|
439 | 449 | /**
|
@@ -579,6 +589,9 @@ public function initiatePasswordReset($email, $template, $websiteId = null)
|
579 | 589 | // load customer by email
|
580 | 590 | $customer = $this->customerRepository->get($email, $websiteId);
|
581 | 591 |
|
| 592 | + // No need to validate customer address while saving customer reset password token |
| 593 | + $this->disableAddressValidation($customer); |
| 594 | + |
582 | 595 | $newPasswordToken = $this->mathRandom->getUniqueHash();
|
583 | 596 | $this->changeResetPasswordLinkToken($customer, $newPasswordToken);
|
584 | 597 |
|
@@ -669,6 +682,10 @@ public function resetPassword($email, $resetToken, $newPassword)
|
669 | 682 | } else {
|
670 | 683 | $customer = $this->customerRepository->get($email);
|
671 | 684 | }
|
| 685 | + |
| 686 | + // No need to validate customer address while saving customer reset password token |
| 687 | + $this->disableAddressValidation($customer); |
| 688 | + |
672 | 689 | //Validate Token and new password strength
|
673 | 690 | $this->validateResetPasswordToken($customer->getId(), $resetToken);
|
674 | 691 | $this->credentialsValidator->checkPasswordDifferentFromEmail(
|
@@ -926,6 +943,8 @@ public function getDefaultShippingAddress($customerId)
|
926 | 943 | * @param string $redirectUrl
|
927 | 944 | * @param array $extensions
|
928 | 945 | * @return void
|
| 946 | + * @throws LocalizedException |
| 947 | + * @throws NoSuchEntityException |
929 | 948 | */
|
930 | 949 | protected function sendEmailConfirmation(CustomerInterface $customer, $redirectUrl, $extensions = [])
|
931 | 950 | {
|
@@ -987,7 +1006,10 @@ public function changePasswordById($customerId, $currentPassword, $newPassword)
|
987 | 1006 | * @param string $newPassword
|
988 | 1007 | * @return bool true on success
|
989 | 1008 | * @throws InputException
|
| 1009 | + * @throws InputMismatchException |
990 | 1010 | * @throws InvalidEmailOrPasswordException
|
| 1011 | + * @throws LocalizedException |
| 1012 | + * @throws NoSuchEntityException |
991 | 1013 | * @throws UserLockedException
|
992 | 1014 | */
|
993 | 1015 | private function changePasswordForCustomer($customer, $currentPassword, $newPassword)
|
@@ -1202,6 +1224,8 @@ protected function sendNewAccountEmail(
|
1202 | 1224 | *
|
1203 | 1225 | * @param CustomerInterface $customer
|
1204 | 1226 | * @return $this
|
| 1227 | + * @throws LocalizedException |
| 1228 | + * @throws NoSuchEntityException |
1205 | 1229 | * @deprecated 100.1.0
|
1206 | 1230 | */
|
1207 | 1231 | protected function sendPasswordResetNotificationEmail($customer)
|
@@ -1264,6 +1288,7 @@ protected function getTemplateTypes()
|
1264 | 1288 | * @param int|null $storeId
|
1265 | 1289 | * @param string $email
|
1266 | 1290 | * @return $this
|
| 1291 | + * @throws MailException |
1267 | 1292 | * @deprecated 100.1.0
|
1268 | 1293 | */
|
1269 | 1294 | protected function sendEmailTemplate(
|
@@ -1379,6 +1404,9 @@ public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
|
1379 | 1404 | * @param string $passwordLinkToken
|
1380 | 1405 | * @return bool
|
1381 | 1406 | * @throws InputException
|
| 1407 | + * @throws InputMismatchException |
| 1408 | + * @throws LocalizedException |
| 1409 | + * @throws NoSuchEntityException |
1382 | 1410 | */
|
1383 | 1411 | public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
|
1384 | 1412 | {
|
@@ -1407,6 +1435,8 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
|
1407 | 1435 | *
|
1408 | 1436 | * @param CustomerInterface $customer
|
1409 | 1437 | * @return $this
|
| 1438 | + * @throws LocalizedException |
| 1439 | + * @throws NoSuchEntityException |
1410 | 1440 | * @deprecated 100.1.0
|
1411 | 1441 | */
|
1412 | 1442 | public function sendPasswordReminderEmail($customer)
|
@@ -1434,6 +1464,8 @@ public function sendPasswordReminderEmail($customer)
|
1434 | 1464 | *
|
1435 | 1465 | * @param CustomerInterface $customer
|
1436 | 1466 | * @return $this
|
| 1467 | + * @throws LocalizedException |
| 1468 | + * @throws NoSuchEntityException |
1437 | 1469 | * @deprecated 100.1.0
|
1438 | 1470 | */
|
1439 | 1471 | public function sendPasswordResetConfirmationEmail($customer)
|
@@ -1478,6 +1510,7 @@ protected function getAddressById(CustomerInterface $customer, $addressId)
|
1478 | 1510 | *
|
1479 | 1511 | * @param CustomerInterface $customer
|
1480 | 1512 | * @return Data\CustomerSecure
|
| 1513 | + * @throws NoSuchEntityException |
1481 | 1514 | * @deprecated 100.1.0
|
1482 | 1515 | */
|
1483 | 1516 | protected function getFullCustomerObject($customer)
|
@@ -1505,6 +1538,20 @@ public function getPasswordHash($password)
|
1505 | 1538 | return $this->encryptor->getHash($password);
|
1506 | 1539 | }
|
1507 | 1540 |
|
| 1541 | + /** |
| 1542 | + * Disable Customer Address Validation |
| 1543 | + * |
| 1544 | + * @param CustomerInterface $customer |
| 1545 | + * @throws NoSuchEntityException |
| 1546 | + */ |
| 1547 | + private function disableAddressValidation($customer) |
| 1548 | + { |
| 1549 | + foreach ($customer->getAddresses() as $address) { |
| 1550 | + $addressModel = $this->addressRegistry->retrieve($address->getId()); |
| 1551 | + $addressModel->setShouldIgnoreValidation(true); |
| 1552 | + } |
| 1553 | + } |
| 1554 | + |
1508 | 1555 | /**
|
1509 | 1556 | * Get email notification
|
1510 | 1557 | *
|
|
0 commit comments