Skip to content

Commit 4526732

Browse files
committed
MAGETWO-94052: CAPTCHA does not appear in "Log in" popup window
- Added validation if response is undefined
1 parent 7691cd0 commit 4526732

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

app/code/Magento/Captcha/Model/Customer/Plugin/AjaxLogin.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function aroundExecute(
104104
if (!$captchaModel->isCorrect($captchaString)) {
105105
$this->sessionManager->setUsername($username);
106106
$captchaModel->logAttempt($username);
107-
return $this->returnJsonError(__('Incorrect CAPTCHA'));
107+
return $this->returnJsonError(__('Incorrect CAPTCHA'), true);
108108
}
109109
}
110110

@@ -118,11 +118,12 @@ public function aroundExecute(
118118
* Gets Json response.
119119
*
120120
* @param \Magento\Framework\Phrase $phrase
121+
* @param bool $isCaptchaRequired
121122
* @return Json
122123
*/
123-
private function returnJsonError(\Magento\Framework\Phrase $phrase): Json
124+
private function returnJsonError(\Magento\Framework\Phrase $phrase, bool $isCaptchaRequired = false): Json
124125
{
125126
$resultJson = $this->resultJsonFactory->create();
126-
return $resultJson->setData(['errors' => true, 'message' => $phrase]);
127+
return $resultJson->setData(['errors' => true, 'message' => $phrase, 'captcha' => $isCaptchaRequired]);
127128
}
128129
}

app/code/Magento/Captcha/Test/Unit/Model/Customer/Plugin/AjaxLoginTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function testAroundExecuteIncorrectCaptcha()
158158
$this->resultJsonMock
159159
->expects($this->once())
160160
->method('setData')
161-
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA')])
161+
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA'), 'captcha' => true])
162162
->will($this->returnSelf());
163163

164164
$closure = function () {

app/code/Magento/Captcha/view/frontend/web/js/view/checkout/loginCaptcha.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
*/
55

66
define([
7+
'underscore',
78
'Magento_Captcha/js/view/checkout/defaultCaptcha',
89
'Magento_Captcha/js/model/captchaList',
910
'Magento_Customer/js/action/login'
1011
],
11-
function (defaultCaptcha, captchaList, loginAction) {
12+
function (_, defaultCaptcha, captchaList, loginAction) {
1213
'use strict';
1314

1415
return defaultCaptcha.extend({
@@ -25,11 +26,11 @@ define([
2526
this.setCurrentCaptcha(currentCaptcha);
2627

2728
loginAction.registerLoginCallback(function (loginData, response) {
28-
if (!response.errors) {
29+
if (!loginData['captcha_form_id'] || loginData['captcha_form_id'] !== self.formId) {
2930
return;
3031
}
3132

32-
if (!loginData['captcha_form_id'] || loginData['captcha_form_id'] !== self.formId) {
33+
if (_.isUndefined(response) || !response.errors) {
3334
return;
3435
}
3536

app/code/Magento/Customer/view/frontend/web/js/view/authentication-popup.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ define([
8484
if (formElement.validation() &&
8585
formElement.validation('isValid')
8686
) {
87-
this.isLoading(true);
8887
loginAction(loginData);
8988
}
9089

0 commit comments

Comments
 (0)