|
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,6 +369,7 @@ 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)
|
368 | 374 | */
|
369 | 375 | public function __construct(
|
@@ -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 | /**
|
@@ -579,6 +588,9 @@ public function initiatePasswordReset($email, $template, $websiteId = null)
|
579 | 588 | // load customer by email
|
580 | 589 | $customer = $this->customerRepository->get($email, $websiteId);
|
581 | 590 |
|
| 591 | + // No need to validate customer address while saving customer reset password token |
| 592 | + $this->disableAddressValidation($customer); |
| 593 | + |
582 | 594 | $newPasswordToken = $this->mathRandom->getUniqueHash();
|
583 | 595 | $this->changeResetPasswordLinkToken($customer, $newPasswordToken);
|
584 | 596 |
|
@@ -669,6 +681,10 @@ public function resetPassword($email, $resetToken, $newPassword)
|
669 | 681 | } else {
|
670 | 682 | $customer = $this->customerRepository->get($email);
|
671 | 683 | }
|
| 684 | + |
| 685 | + // No need to validate customer address while saving customer reset password token |
| 686 | + $this->disableAddressValidation($customer); |
| 687 | + |
672 | 688 | //Validate Token and new password strength
|
673 | 689 | $this->validateResetPasswordToken($customer->getId(), $resetToken);
|
674 | 690 | $this->credentialsValidator->checkPasswordDifferentFromEmail(
|
@@ -921,6 +937,8 @@ public function getDefaultShippingAddress($customerId)
|
921 | 937 | * @param CustomerInterface $customer
|
922 | 938 | * @param string $redirectUrl
|
923 | 939 | * @return void
|
| 940 | + * @throws LocalizedException |
| 941 | + * @throws NoSuchEntityException |
924 | 942 | */
|
925 | 943 | protected function sendEmailConfirmation(CustomerInterface $customer, $redirectUrl)
|
926 | 944 | {
|
@@ -975,7 +993,10 @@ public function changePasswordById($customerId, $currentPassword, $newPassword)
|
975 | 993 | * @param string $newPassword
|
976 | 994 | * @return bool true on success
|
977 | 995 | * @throws InputException
|
| 996 | + * @throws InputMismatchException |
978 | 997 | * @throws InvalidEmailOrPasswordException
|
| 998 | + * @throws LocalizedException |
| 999 | + * @throws NoSuchEntityException |
979 | 1000 | * @throws UserLockedException
|
980 | 1001 | */
|
981 | 1002 | private function changePasswordForCustomer($customer, $currentPassword, $newPassword)
|
@@ -1190,6 +1211,8 @@ protected function sendNewAccountEmail(
|
1190 | 1211 | *
|
1191 | 1212 | * @param CustomerInterface $customer
|
1192 | 1213 | * @return $this
|
| 1214 | + * @throws LocalizedException |
| 1215 | + * @throws NoSuchEntityException |
1193 | 1216 | * @deprecated 100.1.0
|
1194 | 1217 | */
|
1195 | 1218 | protected function sendPasswordResetNotificationEmail($customer)
|
@@ -1252,6 +1275,7 @@ protected function getTemplateTypes()
|
1252 | 1275 | * @param int|null $storeId
|
1253 | 1276 | * @param string $email
|
1254 | 1277 | * @return $this
|
| 1278 | + * @throws MailException |
1255 | 1279 | * @deprecated 100.1.0
|
1256 | 1280 | */
|
1257 | 1281 | protected function sendEmailTemplate(
|
@@ -1367,6 +1391,9 @@ public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
|
1367 | 1391 | * @param string $passwordLinkToken
|
1368 | 1392 | * @return bool
|
1369 | 1393 | * @throws InputException
|
| 1394 | + * @throws InputMismatchException |
| 1395 | + * @throws LocalizedException |
| 1396 | + * @throws NoSuchEntityException |
1370 | 1397 | */
|
1371 | 1398 | public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
|
1372 | 1399 | {
|
@@ -1394,6 +1421,8 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
|
1394 | 1421 | *
|
1395 | 1422 | * @param CustomerInterface $customer
|
1396 | 1423 | * @return $this
|
| 1424 | + * @throws LocalizedException |
| 1425 | + * @throws NoSuchEntityException |
1397 | 1426 | * @deprecated 100.1.0
|
1398 | 1427 | */
|
1399 | 1428 | public function sendPasswordReminderEmail($customer)
|
@@ -1421,6 +1450,8 @@ public function sendPasswordReminderEmail($customer)
|
1421 | 1450 | *
|
1422 | 1451 | * @param CustomerInterface $customer
|
1423 | 1452 | * @return $this
|
| 1453 | + * @throws LocalizedException |
| 1454 | + * @throws NoSuchEntityException |
1424 | 1455 | * @deprecated 100.1.0
|
1425 | 1456 | */
|
1426 | 1457 | public function sendPasswordResetConfirmationEmail($customer)
|
@@ -1465,6 +1496,7 @@ protected function getAddressById(CustomerInterface $customer, $addressId)
|
1465 | 1496 | *
|
1466 | 1497 | * @param CustomerInterface $customer
|
1467 | 1498 | * @return Data\CustomerSecure
|
| 1499 | + * @throws NoSuchEntityException |
1468 | 1500 | * @deprecated 100.1.0
|
1469 | 1501 | */
|
1470 | 1502 | protected function getFullCustomerObject($customer)
|
@@ -1492,6 +1524,20 @@ public function getPasswordHash($password)
|
1492 | 1524 | return $this->encryptor->getHash($password);
|
1493 | 1525 | }
|
1494 | 1526 |
|
| 1527 | + /** |
| 1528 | + * Disable Customer Address Validation |
| 1529 | + * |
| 1530 | + * @param CustomerInterface $customer |
| 1531 | + * @throws NoSuchEntityException |
| 1532 | + */ |
| 1533 | + private function disableAddressValidation($customer) |
| 1534 | + { |
| 1535 | + foreach ($customer->getAddresses() as $address) { |
| 1536 | + $addressModel = $this->addressRegistry->retrieve($address->getId()); |
| 1537 | + $addressModel->setShouldIgnoreValidation(true); |
| 1538 | + } |
| 1539 | + } |
| 1540 | + |
1495 | 1541 | /**
|
1496 | 1542 | * Get email notification
|
1497 | 1543 | *
|
|
0 commit comments