Skip to content

Commit 64185ae

Browse files
authored
Merge pull request #124 from /issues/123
security-package/issues/123: reCAPTCHA adapters modularity
2 parents 03665ef + 93bcfaa commit 64185ae

File tree

149 files changed

+2968
-1684
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+2968
-1684
lines changed

ReCaptcha/Model/CaptchaValidator.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

ReCaptcha/composer.json

Lines changed: 0 additions & 28 deletions
This file was deleted.

ReCaptcha/etc/acl.xml

Lines changed: 0 additions & 26 deletions
This file was deleted.

ReCaptcha/etc/di.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

ReCaptchaAdminUi/Model/CaptchaConfig.php

Lines changed: 0 additions & 149 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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\ReCaptchaAdminUi\Model;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\ReCaptchaUi\Model\CaptchaTypeResolverInterface;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class CaptchaTypeResolver implements CaptchaTypeResolverInterface
17+
{
18+
private const XML_PATH_TYPE_FOR = 'recaptcha_backend/type_for/';
19+
20+
/**
21+
* @var ScopeConfigInterface
22+
*/
23+
private $scopeConfig;
24+
25+
/**
26+
* @param ScopeConfigInterface $scopeConfig
27+
*/
28+
public function __construct(
29+
ScopeConfigInterface $scopeConfig
30+
) {
31+
$this->scopeConfig = $scopeConfig;
32+
}
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
public function getCaptchaTypeFor(string $key): ?string
38+
{
39+
$type = $this->scopeConfig->getValue(
40+
self::XML_PATH_TYPE_FOR . $key
41+
);
42+
return $type;
43+
}
44+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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\ReCaptchaAdminUi\Model;
9+
10+
use Magento\Framework\Data\OptionSourceInterface;
11+
12+
/**
13+
* Generic class for reCAPTCHA Stores/System Configuration options
14+
* Should not use directly, only as base class for "virtual type" in DI configuration
15+
*
16+
* Extension point for adding reCAPTCHA options
17+
*
18+
* @api
19+
*/
20+
class OptionSource implements OptionSourceInterface
21+
{
22+
/**
23+
* @var array
24+
*/
25+
private $options;
26+
27+
/**
28+
* @param array $options
29+
*/
30+
public function __construct(array $options = [])
31+
{
32+
$this->options = $options;
33+
}
34+
35+
/**
36+
* @inheritDoc
37+
*/
38+
public function toOptionArray(): array
39+
{
40+
return array_values($this->options);
41+
}
42+
}

ReCaptchaAdminUi/composer.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
{
22
"name": "magento/module-re-captcha-admin-ui",
3-
"version": "1.0.0",
4-
"description": "Google reCaptcha integration for Magento2",
3+
"description": "Google reCAPTCHA integration for Magento2",
54
"require": {
65
"php": "~7.1.3||~7.2.0||~7.3.0",
76
"magento/framework": "102.0.*",
87
"magento/module-config": "*",
9-
"magento/module-re-captcha-api": "*"
8+
"magento/module-re-captcha-api": "*",
9+
"magento/module-re-captcha-ui": "*"
1010
},
11-
"authors": [
12-
{
13-
"name": "Riccardo Tempesta",
14-
"email": "[email protected]"
15-
}
16-
],
1711
"type": "magento2-module",
1812
"license": "OSL-3.0",
1913
"autoload": {

ReCaptchaAdminUi/etc/adminhtml/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10-
<preference for="Magento\ReCaptchaApi\Api\CaptchaConfigInterface"
11-
type="Magento\ReCaptchaAdminUi\Model\CaptchaConfig"/>
10+
<preference for="Magento\ReCaptchaUi\Model\CaptchaTypeResolverInterface"
11+
type="Magento\ReCaptchaAdminUi\Model\CaptchaTypeResolver"/>
1212
</config>

0 commit comments

Comments
 (0)