Skip to content

Commit e8fa066

Browse files
authored
ENGCOM-5733: magento/magento2#: “Bad request” is never shown #24331
2 parents 186efd4 + 336ea28 commit e8fa066

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@
66
*/
77
namespace Magento\Customer\Controller\Account;
88

9-
use Magento\Customer\Model\Url;
10-
use Magento\Framework\App\Action\Context;
11-
use Magento\Customer\Model\Session;
12-
use Magento\Framework\App\Config\ScopeConfigInterface;
13-
use Magento\Store\Model\StoreManagerInterface;
149
use Magento\Customer\Api\AccountManagementInterface;
1510
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Customer\Controller\AbstractAccount;
1612
use Magento\Customer\Helper\Address;
13+
use Magento\Customer\Model\Session;
14+
use Magento\Customer\Model\Url;
15+
use Magento\Framework\App\Action\Context;
16+
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
17+
use Magento\Framework\App\Config\ScopeConfigInterface;
18+
use Magento\Framework\Controller\ResultFactory;
1719
use Magento\Framework\UrlFactory;
1820
use Magento\Framework\Exception\StateException;
1921
use Magento\Store\Model\ScopeInterface;
20-
use Magento\Framework\Controller\ResultFactory;
22+
use Magento\Store\Model\StoreManagerInterface;
2123

2224
/**
2325
* Class Confirm
2426
*
2527
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2628
*/
27-
class Confirm extends \Magento\Customer\Controller\AbstractAccount
29+
class Confirm extends AbstractAccount implements HttpGetActionInterface
2830
{
2931
/**
3032
* @var \Magento\Framework\App\Config\ScopeConfigInterface
@@ -147,13 +149,16 @@ public function execute()
147149
$resultRedirect->setPath('*/*/');
148150
return $resultRedirect;
149151
}
150-
try {
151-
$customerId = $this->getRequest()->getParam('id', false);
152-
$key = $this->getRequest()->getParam('key', false);
153-
if (empty($customerId) || empty($key)) {
154-
throw new \Exception(__('Bad request.'));
155-
}
156152

153+
$customerId = $this->getRequest()->getParam('id', false);
154+
$key = $this->getRequest()->getParam('key', false);
155+
if (empty($customerId) || empty($key)) {
156+
$this->messageManager->addErrorMessage(__('Bad request.'));
157+
$url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
158+
return $resultRedirect->setUrl($this->_redirect->error($url));
159+
}
160+
161+
try {
157162
// log in and send greeting email
158163
$customerEmail = $this->customerRepository->getById($customerId)->getEmail();
159164
$customer = $this->customerAccountManagement->activate($customerEmail, $key);

app/code/Magento/Customer/Test/Unit/Controller/Account/ConfirmTest.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,9 @@ public function testNoCustomerIdInRequest($customerId, $key)
203203
->with($this->equalTo('key'), false)
204204
->will($this->returnValue($key));
205205

206-
$exception = new \Exception('Bad request.');
207206
$this->messageManagerMock->expects($this->once())
208-
->method('addException')
209-
->with($this->equalTo($exception), $this->equalTo('There was an error confirming the account'));
207+
->method('addErrorMessage')
208+
->with(__('Bad request.'));
210209

211210
$testUrl = 'http://example.com';
212211
$this->urlMock->expects($this->once())
@@ -255,10 +254,12 @@ public function testSuccessMessage($customerId, $key, $vatValidationEnabled, $ad
255254

256255
$this->requestMock->expects($this->any())
257256
->method('getParam')
258-
->willReturnMap([
259-
['id', false, $customerId],
260-
['key', false, $key],
261-
]);
257+
->willReturnMap(
258+
[
259+
['id', false, $customerId],
260+
['key', false, $key],
261+
]
262+
);
262263

263264
$this->customerRepositoryMock->expects($this->any())
264265
->method('getById')
@@ -372,11 +373,13 @@ public function testSuccessRedirect(
372373

373374
$this->requestMock->expects($this->any())
374375
->method('getParam')
375-
->willReturnMap([
376-
['id', false, $customerId],
377-
['key', false, $key],
378-
['back_url', false, $backUrl],
379-
]);
376+
->willReturnMap(
377+
[
378+
['id', false, $customerId],
379+
['key', false, $key],
380+
['back_url', false, $backUrl],
381+
]
382+
);
380383

381384
$this->customerRepositoryMock->expects($this->any())
382385
->method('getById')

0 commit comments

Comments
 (0)