Skip to content

Commit ae7bfb6

Browse files
committed
Disable captcha storefont config still load captcha js files
1 parent 0cfe4a3 commit ae7bfb6

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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\Captcha\Plugin;
9+
10+
use Magento\Captcha\Helper\Data as HelperCaptcha;
11+
use Magento\Customer\Block\Account\AuthenticationPopup;
12+
use Magento\Customer\Model\Context;
13+
use Magento\Framework\App\Http\Context as HttpContext;
14+
15+
/**
16+
* Check need captcha for authentication popup
17+
*/
18+
class CheckCaptchaOnStorefront
19+
{
20+
/**
21+
* @var HelperCaptcha
22+
*/
23+
protected $helper;
24+
25+
/**
26+
* Customer session
27+
*
28+
* @var HttpContext
29+
*/
30+
protected $httpContext;
31+
32+
/**
33+
* CheckCaptchaOnStorefront constructor
34+
*
35+
* @param HelperCaptcha $helper
36+
* @param HttpContext $httpContext
37+
*/
38+
public function __construct(
39+
HelperCaptcha $helper,
40+
HttpContext $httpContext
41+
) {
42+
$this->helper = $helper;
43+
$this->httpContext = $httpContext;
44+
}
45+
46+
/**
47+
* Remove template when loggin or disable captcha storefront
48+
*
49+
* @param AuthenticationPopup $subject
50+
* @param string $result
51+
* @return string
52+
*
53+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
54+
*/
55+
public function afterGetTemplate(
56+
AuthenticationPopup $subject,
57+
$result
58+
) {
59+
if ($this->isLoggedIn() || !$this->helper->getConfig('enable')) {
60+
return '';
61+
}
62+
63+
return $result;
64+
}
65+
66+
/**
67+
* Is logged in
68+
*
69+
* @return bool
70+
*/
71+
private function isLoggedIn()
72+
{
73+
return $this->httpContext->getValue(Context::CONTEXT_AUTH);
74+
}
75+
}

app/code/Magento/Captcha/etc/frontend/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@
3737
<type name="Magento\Sales\Api\OrderManagementInterface">
3838
<plugin name="reset_payment_attempts_after_order_is_placed_plugin" type="Magento\Captcha\Plugin\ResetPaymentAttemptsAfterOrderIsPlacedPlugin"/>
3939
</type>
40+
<type name="Magento\Customer\Block\Account\AuthenticationPopup">
41+
<plugin name="check_captcha_on_storefront" type="Magento\Captcha\Plugin\CheckCaptchaOnStorefront" sortOrder="10"/>
42+
</type>
4043
</config>

0 commit comments

Comments
 (0)