Skip to content

Commit 3d82f43

Browse files
Merge pull request #154 from magento-cia/cia-pre-release-develop-sync-05212024
Cia pre release develop sync 05212024
2 parents d7ab701 + 412fa64 commit 3d82f43

File tree

28 files changed

+1078
-68
lines changed

28 files changed

+1078
-68
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained from
13+
* Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\ReCaptchaResendConfirmationEmail\Model;
18+
19+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
20+
use Magento\ReCaptchaUi\Model\ValidationConfigResolverInterface;
21+
use Magento\ReCaptchaValidationApi\Api\Data\ValidationConfigInterface;
22+
use Magento\ReCaptchaWebapiApi\Api\Data\EndpointInterface;
23+
use Magento\ReCaptchaWebapiApi\Api\WebapiValidationConfigProviderInterface;
24+
use Magento\CustomerGraphQl\Model\Resolver\ResendConfirmationEmail;
25+
26+
/**
27+
* Provide ResendConfirmationEmail related endpoint configuration.
28+
*/
29+
class WebapiConfigProvider implements WebapiValidationConfigProviderInterface
30+
{
31+
/**
32+
* Captcha id from config.
33+
*/
34+
private const CAPTCHA_ID = 'resend_confirmation_email';
35+
36+
/**
37+
* @param IsCaptchaEnabledInterface $isEnabled
38+
* @param ValidationConfigResolverInterface $configResolver
39+
*/
40+
public function __construct(
41+
private readonly IsCaptchaEnabledInterface $isEnabled,
42+
private readonly ValidationConfigResolverInterface $configResolver
43+
) {
44+
}
45+
46+
/**
47+
* @inheritDoc
48+
*/
49+
public function getConfigFor(EndpointInterface $endpoint): ?ValidationConfigInterface
50+
{
51+
if ($endpoint->getServiceMethod() === 'resolve'
52+
&& $endpoint->getServiceClass() === ResendConfirmationEmail::class
53+
) {
54+
if ($this->isEnabled->isCaptchaEnabledFor(self::CAPTCHA_ID)) {
55+
return $this->configResolver->get(self::CAPTCHA_ID);
56+
}
57+
}
58+
59+
return null;
60+
}
61+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained from
13+
* Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\ReCaptchaResendConfirmationEmail\Observer;
18+
19+
use Magento\Framework\App\Action\Action;
20+
use Magento\Framework\App\Response\RedirectInterface;
21+
use Magento\Framework\Event\Observer;
22+
use Magento\Framework\Event\ObserverInterface;
23+
use Magento\Framework\Exception\LocalizedException;
24+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
25+
use Magento\ReCaptchaUi\Model\RequestHandlerInterface;
26+
27+
class ResendConfirmationEmailObserver implements ObserverInterface
28+
{
29+
private const KEY = 'resend_confirmation_email';
30+
31+
/**
32+
* @param RedirectInterface $redirect
33+
* @param IsCaptchaEnabledInterface $isCaptchaEnabled
34+
* @param RequestHandlerInterface $requestHandler
35+
*/
36+
public function __construct(
37+
private readonly RedirectInterface $redirect,
38+
private readonly IsCaptchaEnabledInterface $isCaptchaEnabled,
39+
private readonly RequestHandlerInterface $requestHandler
40+
) {
41+
}
42+
43+
/**
44+
* Check captcha result if captcha has been enabled for this endpoint
45+
*
46+
* @param Observer $observer
47+
* @return void
48+
* @throws LocalizedException
49+
*/
50+
public function execute(Observer $observer): void
51+
{
52+
if ($this->isCaptchaEnabled->isCaptchaEnabledFor(self::KEY)) {
53+
/** @var Action $controller */
54+
$controller = $observer->getControllerAction();
55+
$request = $controller->getRequest();
56+
$response = $controller->getResponse();
57+
$redirectOnFailureUrl = $this->redirect->getRefererUrl();
58+
59+
$this->requestHandler->execute(self::KEY, $request, $response, $redirectOnFailureUrl);
60+
}
61+
}
62+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Magento reCAPTCHA
2+
3+
Google reCAPTCHA ensures that a human being, rather than a computer (or “bot”), is interacting with your website. Unlike the standard Magento CAPTCHA, Google reCAPTCHA provides enhanced security with a selection of different display options and methods. Additional website traffic information is available in the dashboard of your Google reCAPTCHA account.
4+
5+
This module provides the reCAPTCHA implementations related to resend confirmation email action.
6+
7+
For more information please visit the [Magento document for reCAPTCHA](https://docs.magento.com/user-guide/stores/security-google-recaptcha.html).
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained from
13+
* Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\ReCaptchaResendConfirmationEmail\Test\Api\GraphQl\ResendConfirmationEmail;
18+
19+
use Magento\TestFramework\Fixture\Config as ConfigFixture;
20+
use Magento\TestFramework\TestCase\GraphQlAbstract;
21+
22+
/**
23+
* GraphQl test for resend confirmation email functionality with ReCaptcha enabled.
24+
*/
25+
class ResendConfirmationEmailTest extends GraphQlAbstract
26+
{
27+
28+
#[
29+
ConfigFixture('recaptcha_frontend/type_invisible/public_key', 'test_public_key'),
30+
ConfigFixture('recaptcha_frontend/type_invisible/private_key', 'test_private_key'),
31+
ConfigFixture('recaptcha_frontend/type_for/resend_confirmation_email', 'invisible')
32+
]
33+
public function testResendConfirmationEmailReCaptchaValidationFailed(): void
34+
{
35+
$query = $this->getQuery("[email protected]");
36+
37+
$this->expectExceptionMessage('ReCaptcha validation failed, please try again');
38+
$this->graphQlMutation($query);
39+
}
40+
41+
/**
42+
* @param string $email
43+
* @return string
44+
*/
45+
private function getQuery(string $email): string
46+
{
47+
return <<<QUERY
48+
mutation {
49+
resendConfirmationEmail(
50+
email: "{$email}"
51+
)
52+
}
53+
QUERY;
54+
}
55+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "magento/module-re-captcha-resend-confirmation-email",
3+
"description": "Google reCAPTCHA integration for Magento2",
4+
"require": {
5+
"php": "~8.1.0||~8.2.0||~8.3.0",
6+
"magento/framework": "*",
7+
"magento/module-re-captcha-ui": "*",
8+
"magento/module-re-captcha-validation-api": "*",
9+
"magento/module-re-captcha-webapi-api": "*",
10+
"magento/module-customer-graph-ql": "*"
11+
},
12+
"type": "magento2-module",
13+
"license": "OSL-3.0",
14+
"autoload": {
15+
"files": [
16+
"registration.php"
17+
],
18+
"psr-4": {
19+
"Magento\\ReCaptchaResendConfirmationEmail\\": ""
20+
}
21+
}
22+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/************************************************************************
4+
*
5+
* Copyright 2024 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
* ************************************************************************
17+
*/
18+
-->
19+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
21+
<system>
22+
<section id="recaptcha_frontend">
23+
<group id="type_for">
24+
<field id="resend_confirmation_email" translate="label" type="select" sortOrder="170" showInDefault="1"
25+
showInWebsite="1" showInStore="0" canRestore="1">
26+
<label>Enable for Resend Confirmation Email</label>
27+
<source_model>Magento\ReCaptchaAdminUi\Model\OptionSource\Type</source_model>
28+
</field>
29+
</group>
30+
</section>
31+
</system>
32+
</config>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/************************************************************************
4+
*
5+
* Copyright 2024 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
* ************************************************************************
17+
*/
18+
-->
19+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
21+
<default>
22+
<recaptcha_frontend>
23+
<type_for>
24+
<resend_confirmation_email/>
25+
</type_for>
26+
</recaptcha_frontend>
27+
</default>
28+
</config>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/************************************************************************
4+
*
5+
* Copyright 2024 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
* ************************************************************************
17+
*/
18+
-->
19+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
21+
<type name="Magento\ReCaptchaWebapiApi\Model\CompositeWebapiValidationConfigProvider">
22+
<arguments>
23+
<argument name="providers" xsi:type="array">
24+
<item name="resend_confirmation_email" xsi:type="object">Magento\ReCaptchaResendConfirmationEmail\Model\WebapiConfigProvider</item>
25+
</argument>
26+
</arguments>
27+
</type>
28+
</config>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/************************************************************************
4+
*
5+
* Copyright 2024 Adobe
6+
* All Rights Reserved.
7+
*
8+
* NOTICE: All information contained herein is, and remains
9+
* the property of Adobe and its suppliers, if any. The intellectual
10+
* and technical concepts contained herein are proprietary to Adobe
11+
* and its suppliers and are protected by all applicable intellectual
12+
* property laws, including trade secret and copyright laws.
13+
* Dissemination of this information or reproduction of this material
14+
* is strictly forbidden unless prior written permission is obtained
15+
* from Adobe.
16+
* ************************************************************************
17+
*/
18+
-->
19+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
21+
<module name="Magento_ReCaptchaResendConfirmationEmail"/>
22+
</config>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained from
13+
* Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
\Magento\Framework\Component\ComponentRegistrar::register(
18+
\Magento\Framework\Component\ComponentRegistrar::MODULE,
19+
'Magento_ReCaptchaResendConfirmationEmail',
20+
__DIR__
21+
);

0 commit comments

Comments
 (0)