Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 32219a9

Browse files
author
Joan He
authored
Merge pull request #3255 from magento-qwerty/2.3-bugfixes-031018
[Qwerty] Bugfixes
2 parents 2ae0b65 + 150b821 commit 32219a9

File tree

19 files changed

+231
-3589
lines changed

19 files changed

+231
-3589
lines changed

app/code/Magento/Customer/Api/AccountManagementInterface.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\Customer\Api;
99

10+
use Magento\Framework\Exception\InputException;
11+
1012
/**
1113
* Interface for managing customers accounts.
1214
* @api
@@ -144,19 +146,24 @@ public function initiatePasswordReset($email, $template, $websiteId = null);
144146
/**
145147
* Reset customer password.
146148
*
147-
* @param string $email
149+
* @param string $email If empty value given then the customer
150+
* will be matched by the RP token.
148151
* @param string $resetToken
149152
* @param string $newPassword
153+
*
150154
* @return bool true on success
151155
* @throws \Magento\Framework\Exception\LocalizedException
156+
* @throws InputException
152157
*/
153158
public function resetPassword($email, $resetToken, $newPassword);
154159

155160
/**
156161
* Check if password reset token is valid.
157162
*
158-
* @param int $customerId
163+
* @param int $customerId If null is given then a customer
164+
* will be matched by the RP token.
159165
* @param string $resetPasswordLinkToken
166+
*
160167
* @return bool True if the token is valid
161168
* @throws \Magento\Framework\Exception\State\InputMismatchException If token is mismatched
162169
* @throws \Magento\Framework\Exception\State\ExpiredException If token is expired

app/code/Magento/Customer/Controller/Account/CreatePassword.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\Customer\Controller\Account;
87

98
use Magento\Customer\Api\AccountManagementInterface;
109
use Magento\Customer\Model\Session;
10+
use Magento\Framework\App\Action\HttpGetActionInterface;
1111
use Magento\Framework\View\Result\PageFactory;
1212
use Magento\Framework\App\Action\Context;
1313

14-
class CreatePassword extends \Magento\Customer\Controller\AbstractAccount
14+
/**
15+
* Class CreatePassword
16+
*
17+
* @package Magento\Customer\Controller\Account
18+
*/
19+
class CreatePassword extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface
1520
{
1621
/**
1722
* @var \Magento\Customer\Api\AccountManagementInterface
@@ -54,27 +59,27 @@ public function __construct(
5459
public function execute()
5560
{
5661
$resetPasswordToken = (string)$this->getRequest()->getParam('token');
57-
$customerId = (int)$this->getRequest()->getParam('id');
58-
$isDirectLink = $resetPasswordToken != '' && $customerId != 0;
62+
$isDirectLink = $resetPasswordToken != '';
5963
if (!$isDirectLink) {
6064
$resetPasswordToken = (string)$this->session->getRpToken();
61-
$customerId = (int)$this->session->getRpCustomerId();
6265
}
6366

6467
try {
65-
$this->accountManagement->validateResetPasswordLinkToken($customerId, $resetPasswordToken);
68+
$this->accountManagement->validateResetPasswordLinkToken(null, $resetPasswordToken);
6669

6770
if ($isDirectLink) {
6871
$this->session->setRpToken($resetPasswordToken);
69-
$this->session->setRpCustomerId($customerId);
7072
$resultRedirect = $this->resultRedirectFactory->create();
7173
$resultRedirect->setPath('*/*/createpassword');
74+
7275
return $resultRedirect;
7376
} else {
7477
/** @var \Magento\Framework\View\Result\Page $resultPage */
7578
$resultPage = $this->resultPageFactory->create();
76-
$resultPage->getLayout()->getBlock('resetPassword')->setCustomerId($customerId)
79+
$resultPage->getLayout()
80+
->getBlock('resetPassword')
7781
->setResetPasswordLinkToken($resetPasswordToken);
82+
7883
return $resultPage;
7984
}
8085
} catch (\Exception $exception) {

app/code/Magento/Customer/Controller/Account/EditPost.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Customer\Model\CustomerExtractor;
2323
use Magento\Customer\Model\Session;
2424
use Magento\Framework\App\Action\Context;
25+
use Magento\Framework\Escaper;
2526
use Magento\Framework\Exception\InputException;
2627
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
2728
use Magento\Framework\Exception\State\UserLockedException;
@@ -79,28 +80,36 @@ class EditPost extends AbstractAccount implements CsrfAwareActionInterface, Http
7980
*/
8081
private $customerMapper;
8182

83+
/**
84+
* @var Escaper
85+
*/
86+
private $escaper;
87+
8288
/**
8389
* @param Context $context
8490
* @param Session $customerSession
8591
* @param AccountManagementInterface $customerAccountManagement
8692
* @param CustomerRepositoryInterface $customerRepository
8793
* @param Validator $formKeyValidator
8894
* @param CustomerExtractor $customerExtractor
95+
* @param Escaper|null $escaper
8996
*/
9097
public function __construct(
9198
Context $context,
9299
Session $customerSession,
93100
AccountManagementInterface $customerAccountManagement,
94101
CustomerRepositoryInterface $customerRepository,
95102
Validator $formKeyValidator,
96-
CustomerExtractor $customerExtractor
103+
CustomerExtractor $customerExtractor,
104+
?Escaper $escaper = null
97105
) {
98106
parent::__construct($context);
99107
$this->session = $customerSession;
100108
$this->customerAccountManagement = $customerAccountManagement;
101109
$this->customerRepository = $customerRepository;
102110
$this->formKeyValidator = $formKeyValidator;
103111
$this->customerExtractor = $customerExtractor;
112+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
104113
}
105114

106115
/**
@@ -196,7 +205,7 @@ public function execute()
196205
$this->messageManager->addSuccess(__('You saved the account information.'));
197206
return $resultRedirect->setPath('customer/account');
198207
} catch (InvalidEmailOrPasswordException $e) {
199-
$this->messageManager->addError($e->getMessage());
208+
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
200209
} catch (UserLockedException $e) {
201210
$message = __(
202211
'The account sign-in was incorrect or your account is disabled temporarily. '
@@ -207,9 +216,9 @@ public function execute()
207216
$this->messageManager->addError($message);
208217
return $resultRedirect->setPath('customer/account/login');
209218
} catch (InputException $e) {
210-
$this->messageManager->addError($e->getMessage());
219+
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($e->getMessage()));
211220
foreach ($e->getErrors() as $error) {
212-
$this->messageManager->addError($error->getMessage());
221+
$this->messageManager->addErrorMessage($this->escaper->escapeHtml($error->getMessage()));
213222
}
214223
} catch (\Magento\Framework\Exception\LocalizedException $e) {
215224
$this->messageManager->addError($e->getMessage());

app/code/Magento/Customer/Controller/Account/ResetPasswordPost.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
@@ -10,11 +9,16 @@
109
use Magento\Customer\Api\CustomerRepositoryInterface;
1110
use Magento\Customer\Model\Session;
1211
use Magento\Framework\App\Action\Context;
12+
use Magento\Framework\App\Action\HttpPostActionInterface;
1313
use Magento\Framework\Exception\InputException;
1414
use Magento\Customer\Model\Customer\CredentialsValidator;
15-
use Magento\Framework\App\ObjectManager;
1615

17-
class ResetPasswordPost extends \Magento\Customer\Controller\AbstractAccount
16+
/**
17+
* Class ResetPasswordPost
18+
*
19+
* @package Magento\Customer\Controller\Account
20+
*/
21+
class ResetPasswordPost extends \Magento\Customer\Controller\AbstractAccount implements HttpPostActionInterface
1822
{
1923
/**
2024
* @var \Magento\Customer\Api\AccountManagementInterface
@@ -31,17 +35,14 @@ class ResetPasswordPost extends \Magento\Customer\Controller\AbstractAccount
3135
*/
3236
protected $session;
3337

34-
/**
35-
* @var CredentialsValidator
36-
*/
37-
private $credentialsValidator;
38-
3938
/**
4039
* @param Context $context
4140
* @param Session $customerSession
4241
* @param AccountManagementInterface $accountManagement
4342
* @param CustomerRepositoryInterface $customerRepository
4443
* @param CredentialsValidator|null $credentialsValidator
44+
*
45+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4546
*/
4647
public function __construct(
4748
Context $context,
@@ -53,8 +54,6 @@ public function __construct(
5354
$this->session = $customerSession;
5455
$this->accountManagement = $accountManagement;
5556
$this->customerRepository = $customerRepository;
56-
$this->credentialsValidator = $credentialsValidator ?: ObjectManager::getInstance()
57-
->get(CredentialsValidator::class);
5857
parent::__construct($context);
5958
}
6059

@@ -70,29 +69,32 @@ public function execute()
7069
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
7170
$resultRedirect = $this->resultRedirectFactory->create();
7271
$resetPasswordToken = (string)$this->getRequest()->getQuery('token');
73-
$customerId = (int)$this->getRequest()->getQuery('id');
7472
$password = (string)$this->getRequest()->getPost('password');
7573
$passwordConfirmation = (string)$this->getRequest()->getPost('password_confirmation');
7674

7775
if ($password !== $passwordConfirmation) {
7876
$this->messageManager->addError(__("New Password and Confirm New Password values didn't match."));
79-
$resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
77+
$resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]);
78+
8079
return $resultRedirect;
8180
}
8281
if (iconv_strlen($password) <= 0) {
8382
$this->messageManager->addError(__('Please enter a new password.'));
84-
$resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
83+
$resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]);
84+
8585
return $resultRedirect;
8686
}
8787

8888
try {
89-
$customerEmail = $this->customerRepository->getById($customerId)->getEmail();
90-
$this->credentialsValidator->checkPasswordDifferentFromEmail($customerEmail, $password);
91-
$this->accountManagement->resetPassword($customerEmail, $resetPasswordToken, $password);
89+
$this->accountManagement->resetPassword(
90+
null,
91+
$resetPasswordToken,
92+
$password
93+
);
9294
$this->session->unsRpToken();
93-
$this->session->unsRpCustomerId();
9495
$this->messageManager->addSuccess(__('You updated your password.'));
9596
$resultRedirect->setPath('*/*/login');
97+
9698
return $resultRedirect;
9799
} catch (InputException $e) {
98100
$this->messageManager->addError($e->getMessage());
@@ -102,7 +104,8 @@ public function execute()
102104
} catch (\Exception $exception) {
103105
$this->messageManager->addError(__('Something went wrong while saving the new password.'));
104106
}
105-
$resultRedirect->setPath('*/*/createPassword', ['id' => $customerId, 'token' => $resetPasswordToken]);
107+
$resultRedirect->setPath('*/*/createPassword', ['token' => $resetPasswordToken]);
108+
106109
return $resultRedirect;
107110
}
108111
}

0 commit comments

Comments
 (0)