Skip to content

Commit

Permalink
ENGCOM-3056: Fix the issue with reset password when customer has addr…
Browse files Browse the repository at this point in the history
…ess from not allowed country #18179
  • Loading branch information
sidolov authored Dec 20, 2018
2 parents 19fd585 + 8dd0fbb commit 9b76f0a
Show file tree
Hide file tree
Showing 2 changed files with 2,171 additions and 4 deletions.
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 @@ -926,6 +943,8 @@ public function getDefaultShippingAddress($customerId)
* @param string $redirectUrl
* @param array $extensions
* @return void
* @throws LocalizedException
* @throws NoSuchEntityException
*/
protected function sendEmailConfirmation(CustomerInterface $customer, $redirectUrl, $extensions = [])
{
Expand Down Expand Up @@ -987,7 +1006,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 @@ -1202,6 +1224,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 @@ -1264,6 +1288,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 @@ -1379,6 +1404,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 @@ -1407,6 +1435,8 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
*
* @param CustomerInterface $customer
* @return $this