Skip to content

Commit dc3d3be

Browse files
committed
ACP2E-222: Magento forms can be submitted before the Google Recaptcha appears in the form
1 parent 95ff13b commit dc3d3be

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ReCaptchaCustomer\Plugin\Customer;
9+
10+
use Magento\Framework\Exception\InputException;
11+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
12+
use Magento\Customer\ViewModel\CreateAccountButton;
13+
14+
/**
15+
* Disable button Create Account while captcha is loading
16+
*/
17+
class DisableCreateAccountButton
18+
{
19+
/**
20+
* @var IsCaptchaEnabledInterface
21+
*/
22+
private $isCaptchaEnabled;
23+
24+
/**
25+
* @param IsCaptchaEnabledInterface $isCaptchaEnabled
26+
*/
27+
public function __construct(
28+
IsCaptchaEnabledInterface $isCaptchaEnabled
29+
) {
30+
$this->isCaptchaEnabled = $isCaptchaEnabled;
31+
}
32+
33+
/**
34+
* Temporally disable button Create Account while captcha is loading
35+
*
36+
* @param CreateAccountButton $subject
37+
* @return bool
38+
* @throws InputException
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function afterDisabled(CreateAccountButton $subject): bool
42+
{
43+
$key = 'customer_create';
44+
return $this->isCaptchaEnabled->isCaptchaEnabledFor($key);
45+
}
46+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ReCaptchaCustomer\Plugin\Customer;
9+
10+
use Magento\Framework\Exception\InputException;
11+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
12+
use Magento\ReCaptchaUi\Model\UiConfigResolverInterface;
13+
use Magento\Customer\ViewModel\LoginButton;
14+
15+
/**
16+
* Disable Login button while captcha is loading
17+
*/
18+
class DisableLoginButton
19+
{
20+
/**
21+
* @var IsCaptchaEnabledInterface
22+
*/
23+
private $isCaptchaEnabled;
24+
25+
/**
26+
* @param UiConfigResolverInterface $captchaUiConfigResolver
27+
* @param IsCaptchaEnabledInterface $isCaptchaEnabled
28+
*/
29+
public function __construct(
30+
UiConfigResolverInterface $captchaUiConfigResolver,
31+
IsCaptchaEnabledInterface $isCaptchaEnabled
32+
) {
33+
$this->captchaUiConfigResolver = $captchaUiConfigResolver;
34+
$this->isCaptchaEnabled = $isCaptchaEnabled;
35+
}
36+
37+
/**
38+
* Temporally disable Login button while captcha is loading
39+
*
40+
* @param LoginButton $subject
41+
* @return bool
42+
* @throws InputException
43+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
44+
*/
45+
public function afterDisabled(LoginButton $subject): bool
46+
{
47+
$key = 'customer_login';
48+
return $this->isCaptchaEnabled->isCaptchaEnabledFor($key);
49+
}
50+
}

ReCaptchaCustomer/etc/frontend/di.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,12 @@
2020
<plugin sortOrder="1" name="inject_recaptcha_in_authentication_popup"
2121
type="Magento\ReCaptchaCustomer\Plugin\Block\Account\InjectRecaptchaInAuthenticationPopup"/>
2222
</type>
23-
23+
<type name="Magento\Customer\ViewModel\LoginButton">
24+
<plugin sortOrder="1" name="recaptcha_disable_login_button"
25+
type="Magento\ReCaptchaCustomer\Plugin\Customer\DisableLoginButton"/>
26+
</type>
27+
<type name="Magento\Customer\ViewModel\CreateAccountButton">
28+
<plugin sortOrder="1" name="recaptcha_disable_create_account_button"
29+
type="Magento\ReCaptchaCustomer\Plugin\Customer\DisableCreateAccountButton"/>
30+
</type>
2431
</config>

ReCaptchaFrontendUi/view/frontend/web/js/reCaptcha.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ define(
174174
} else {
175175
this.tokenField = null;
176176
}
177+
if ($('#send2').length > 0) {$('#send2').prop('disabled', false);}
177178
},
178179

179180
/**

0 commit comments

Comments
 (0)