Skip to content
55 changes: 51 additions & 4 deletions app/code/Magento/Customer/Model/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Magento\Customer\Model\Customer as CustomerModel;
use Magento\Customer\Model\Customer\CredentialsValidator;
use Magento\Customer\Model\Metadata\Validator;
use Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory;
use Magento\Eav\Model\Validator\Attribute\Backend;
use Magento\Framework\Api\ExtensibleDataObjectConverter;
use Magento\Framework\Api\SearchCriteriaBuilder;
Expand Down Expand Up @@ -45,14 +46,13 @@
use Magento\Framework\Phrase;
use Magento\Framework\Reflection\DataObjectProcessor;
use Magento\Framework\Registry;
use Magento\Framework\Session\SaveHandlerInterface;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Framework\Stdlib\DateTime;
use Magento\Framework\Stdlib\StringUtils as StringHelper;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface as PsrLogger;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Framework\Session\SaveHandlerInterface;
use Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory;

/**
* Handle various customer account actions
Expand Down Expand Up @@ -333,6 +333,11 @@ class AccountManagement implements AccountManagementInterface
*/
private $searchCriteriaBuilder;

/**
* @var AddressRegistry
*/
private $addressRegistry;

/**
* @param CustomerFactory $customerFactory
* @param ManagerInterface $eventManager
Expand Down Expand Up @@ -364,7 +369,9 @@ class AccountManagement implements AccountManagementInterface
* @param SaveHandlerInterface|null $saveHandler
* @param CollectionFactory|null $visitorCollectionFactory
* @param SearchCriteriaBuilder|null $searchCriteriaBuilder
* @param AddressRegistry|null $addressRegistry
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function __construct(
CustomerFactory $customerFactory,
Expand Down Expand Up @@ -396,7 +403,8 @@ public function __construct(
SessionManagerInterface $sessionManager = null,
SaveHandlerInterface $saveHandler = null,
CollectionFactory $visitorCollectionFactory = null,
SearchCriteriaBuilder $searchCriteriaBuilder = null
SearchCriteriaBuilder $searchCriteriaBuilder = null,
AddressRegistry $addressRegistry = null
) {
$this->customerFactory = $customerFactory;
$this->eventManager = $eventManager;
Expand Down Expand Up @@ -434,6 +442,8 @@ public function __construct(
?: ObjectManager::getInstance()->get(CollectionFactory::class);
$this->searchCriteriaBuilder = $searchCriteriaBuilder
?: ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
$this->addressRegistry = $addressRegistry
?: ObjectManager::getInstance()->get(AddressRegistry::class);
}

/**
Expand Down Expand Up @@ -579,6 +589,9 @@ public function initiatePasswordReset($email, $template, $websiteId = null)
// load customer by email
$customer = $this->customerRepository->get($email, $websiteId);

// No need to validate customer address while saving customer reset password token
$this->disableAddressValidation($customer);

$newPasswordToken = $this->mathRandom->getUniqueHash();
$this->changeResetPasswordLinkToken($customer, $newPasswordToken);

Expand Down Expand Up @@ -669,6 +682,10 @@ public function resetPassword($email, $resetToken, $newPassword)
} else {
$customer = $this->customerRepository->get($email);
}

// No need to validate customer address while saving customer reset password token
$this->disableAddressValidation($customer);

//Validate Token and new password strength
$this->validateResetPasswordToken($customer->getId(), $resetToken);
$this->credentialsValidator->checkPasswordDifferentFromEmail(
Expand Down Expand Up @@ -921,6 +938,8 @@ public function getDefaultShippingAddress($customerId)
* @param CustomerInterface $customer
* @param string $redirectUrl
* @return void
* @throws LocalizedException
* @throws NoSuchEntityException
*/
protected function sendEmailConfirmation(CustomerInterface $customer, $redirectUrl)
{
Expand Down Expand Up @@ -975,7 +994,10 @@ public function changePasswordById($customerId, $currentPassword, $newPassword)
* @param string $newPassword
* @return bool true on success
* @throws InputException
* @throws InputMismatchException
* @throws InvalidEmailOrPasswordException
* @throws LocalizedException
* @throws NoSuchEntityException
* @throws UserLockedException
*/
private function changePasswordForCustomer($customer, $currentPassword, $newPassword)
Expand Down Expand Up @@ -1190,6 +1212,8 @@ protected function sendNewAccountEmail(
*
* @param CustomerInterface $customer
* @return $this
* @throws LocalizedException
* @throws NoSuchEntityException
* @deprecated 100.1.0
*/
protected function sendPasswordResetNotificationEmail($customer)
Expand Down Expand Up @@ -1252,6 +1276,7 @@ protected function getTemplateTypes()
* @param int|null $storeId
* @param string $email
* @return $this
* @throws MailException
* @deprecated 100.1.0
*/
protected function sendEmailTemplate(
Expand Down Expand Up @@ -1367,6 +1392,9 @@ public function isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)
* @param string $passwordLinkToken
* @return bool
* @throws InputException
* @throws InputMismatchException
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
{
Expand Down Expand Up @@ -1394,6 +1422,8 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
*
* @param CustomerInterface $customer
* @return $this
* @throws LocalizedException
* @throws NoSuchEntityException
* @deprecated 100.1.0
*/
public function sendPasswordReminderEmail($customer)
Expand Down Expand Up @@ -1421,6 +1451,8 @@ public function sendPasswordReminderEmail($customer)
*
* @param CustomerInterface $customer
* @return $this
* @throws LocalizedException
* @throws NoSuchEntityException
* @deprecated 100.1.0
*/
public function sendPasswordResetConfirmationEmail($customer)
Expand Down Expand Up @@ -1465,6 +1497,7 @@ protected function getAddressById(CustomerInterface $customer, $addressId)
*
* @param CustomerInterface $customer
* @return Data\CustomerSecure
* @throws NoSuchEntityException
* @deprecated 100.1.0
*/
protected function getFullCustomerObject($customer)
Expand Down Expand Up @@ -1492,6 +1525,20 @@ public function getPasswordHash($password)
return $this->encryptor->getHash($password);
}

/**
* Disable Customer Address Validation
*
* @param CustomerInterface $customer
* @throws NoSuchEntityException
*/
private function disableAddressValidation($customer)
{
foreach ($customer->getAddresses() as $address) {
$addressModel = $this->addressRegistry->retrieve($address->getId());
$addressModel->setShouldIgnoreValidation(true);
}
}

/**
* Get email notification
*
Expand Down
Loading