Skip to content

Commit

Permalink
add recaptcha api url setting
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Feb 7, 2021
1 parent 3f3b0b3 commit f5ff14c
Show file tree
Hide file tree
Showing 79 changed files with 404 additions and 390 deletions.
5 changes: 1 addition & 4 deletions ReCaptchaAdminUi/Model/CaptchaTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public function __construct(
*/
public function getCaptchaTypeFor(string $key): ?string
{
$type = $this->scopeConfig->getValue(
self::XML_PATH_TYPE_FOR . $key
);
return $type;
return $this->scopeConfig->getValue(self::XML_PATH_TYPE_FOR . $key);
}
}
10 changes: 2 additions & 8 deletions ReCaptchaAdminUi/Model/ErrorMessageConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,14 @@ public function __construct(
*/
public function getTechnicalFailureMessage(): string
{
return $this->scopeConfig->getValue(
self::XML_PATH_TECHNICAL,
ScopeInterface::SCOPE_STORE
);
return (string)$this->scopeConfig->getValue(self::XML_PATH_TECHNICAL, ScopeInterface::SCOPE_STORE);
}

/**
* @inheritdoc
*/
public function getValidationFailureMessage(): string
{
return $this->scopeConfig->getValue(
self::XML_PATH_VALIDATION,
ScopeInterface::SCOPE_STORE
);
return (string)$this->scopeConfig->getValue(self::XML_PATH_VALIDATION, ScopeInterface::SCOPE_STORE);
}
}
7 changes: 4 additions & 3 deletions ReCaptchaAdminUi/Model/OptionSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\ReCaptchaAdminUi\Model;

use Magento\Framework\Data\OptionSourceInterface;
use function array_values;

/**
* Generic class for reCAPTCHA Stores/System Configuration options
Expand All @@ -29,14 +30,14 @@ class OptionSource implements OptionSourceInterface
*/
public function __construct(array $options = [])
{
$this->options = $options;
$this->options = array_values($options);
}

/**
* @inheritDoc
* @inheritdoc
*/
public function toOptionArray(): array
{
return array_values($this->options);
return $this->options;
}
}
41 changes: 22 additions & 19 deletions ReCaptchaAdminUi/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,60 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="security" translate="label" sortOrder="200">
<label>Security</label>
</tab>

<section id="recaptcha_backend" translate="label" type="text" sortOrder="600" showInDefault="1"
showInWebsite="0" showInStore="0">
<section id="recaptcha" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="600">
<class>separator-top</class>
<label>Google reCAPTCHA Admin Panel</label>
<label>Google reCAPTCHA</label>
<tab>security</tab>
<resource>Magento_ReCaptchaUi::config</resource>
<group id="api" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="10">
<label>API</label>
<field id="url" type="select" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API URL</label>
<source_model>Magento\ReCaptchaAdminUi\Model\OptionSource\ApiUrl</source_model>
</field>
</group>
</section>

<group id="type_for" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="0"
<section id="recaptcha_backend" translate="label" sortOrder="600" showInDefault="1" showInWebsite="0" showInStore="0">
<class>separator-top</class>
<label>Google reCAPTCHA Admin Panel</label>
<tab>security</tab>
<resource>Magento_ReCaptchaUi::config</resource>
<group id="type_for" translate="label" sortOrder="1000" showInDefault="1" showInWebsite="0"
showInStore="0">
<label>Admin Panel</label>
<field id="recaptcha_backend_info_heading" translate="label" sortOrder="100" showInDefault="1"
showInWebsite="0" showInStore="0" >
<field id="recaptcha_backend_info_heading" translate="label" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" >
<frontend_model>Magento\ReCaptchaAdminUi\Block\Adminhtml\System\Config\Form\Field\Notice</frontend_model>
</field>
</group>

<group id="failure_messages" translate="label" type="text" sortOrder="950" showInDefault="1" showInWebsite="1"
showInStore="1">
<group id="failure_messages" translate="label" sortOrder="950" showInDefault="1" showInWebsite="1" showInStore="1">
<label>reCAPTCHA Failure Messages</label>

<field id="validation_failure_message" translate="label" type="textarea" sortOrder="10" showInDefault="1"
showInWebsite="0" showInStore="0" canRestore="1">
<label>reCAPTCHA Validation Failure Message</label>
</field>

<field id="technical_failure_message" translate="label" type="textarea" sortOrder="20" showInDefault="1"
showInWebsite="0" showInStore="0" canRestore="1">
<label>reCAPTCHA Technical Failure Message</label>
</field>
</group>
</section>

<section id="recaptcha_frontend" translate="label" type="text" sortOrder="700" showInDefault="1"
showInWebsite="1" showInStore="1">
<section id="recaptcha_frontend" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="700">
<class>separator-top</class>
<label>Google reCAPTCHA Storefront</label>
<tab>security</tab>
<resource>Magento_ReCaptchaUi::config</resource>

<group id="type_for" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1"
showInStore="0">
<group id="type_for" translate="label" showInDefault="1" showInWebsite="1" showInStore="0" sortOrder="1000">
<label>Storefront</label>
<field id="recaptcha_frontend_info_heading" translate="label" sortOrder="100" showInDefault="1"
showInWebsite="1" showInStore="0">
<field id="recaptcha_frontend_info_heading" translate="label" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
<frontend_model>Magento\ReCaptchaAdminUi\Block\Adminhtml\System\Config\Form\Field\Notice</frontend_model>
</field>
</group>
Expand Down
20 changes: 16 additions & 4 deletions ReCaptchaAdminUi/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="Magento\ReCaptchaAdminUi\Model\OptionSource\Type"
type="Magento\ReCaptchaAdminUi\Model\OptionSource">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="Magento\ReCaptchaAdminUi\Model\OptionSource\Type" type="Magento\ReCaptchaAdminUi\Model\OptionSource">
<arguments>
<argument name="options" xsi:type="array">
<item name="default" xsi:type="array">
Expand All @@ -18,4 +16,18 @@
</argument>
</arguments>
</virtualType>
<virtualType name="Magento\ReCaptchaAdminUi\Model\OptionSource\ApiUrl" type="Magento\ReCaptchaAdminUi\Model\OptionSource">
<arguments>
<argument name="options" xsi:type="array">
<item name="default" xsi:type="array">
<item name="label" xsi:type="string" translate="true">www.google.com</item>
<item name="value" xsi:type="string">https://www.google.com/recaptcha/api.js</item>
</item>
<item name="global" xsi:type="array">
<item name="label" xsi:type="string" translate="true">www.recaptcha.net</item>
<item name="value" xsi:type="string">https://www.recaptcha.net/recaptcha/api.js</item>
</item>
</argument>
</arguments>
</virtualType>
</config>
11 changes: 8 additions & 3 deletions ReCaptchaAdminUi/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ReCaptchaAdminUi"/>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ReCaptchaAdminUi">
<sequence>
<module name="Magento_Config"/>
<module name="Magento_ReCaptchaUi"/>
<module name="Magento_Store"/>
</sequence>
</module>
</config>
8 changes: 3 additions & 5 deletions ReCaptchaAdminUi/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
declare(strict_types=1);

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magento_ReCaptchaAdminUi',
__DIR__
);
use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_ReCaptchaAdminUi', __DIR__);
3 changes: 2 additions & 1 deletion ReCaptchaCheckout/Block/LayoutProcessor/Checkout/Onepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
* @return array
* @throws InputException
*/
public function process($jsLayout)
public function process($jsLayout): array
{
$key = 'customer_login';
if ($this->isCaptchaEnabled->isCaptchaEnabledFor($key)) {
Expand Down Expand Up @@ -76,6 +76,7 @@ public function process($jsLayout)
unset($jsLayout['components']['checkout']['children']['authentication']['children']['recaptcha']);
}
}

return $jsLayout;
}
}
10 changes: 7 additions & 3 deletions ReCaptchaCheckout/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ReCaptchaCheckout"/>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ReCaptchaCheckout">
<sequence>
<module name="Magento_Checkout"/>
<module name="Magento_ReCaptchaUi"/>
</sequence>
</module>
</config>
8 changes: 3 additions & 5 deletions ReCaptchaCheckout/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
declare(strict_types=1);

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magento_ReCaptchaCheckout',
__DIR__
);
use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_ReCaptchaCheckout', __DIR__);
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
Expand Down Expand Up @@ -55,7 +53,6 @@
</item>
</item>
</item>

<item name="authentication" xsi:type="array">
<item name="children" xsi:type="array">
<item name="recaptcha" xsi:type="array">
Expand Down
9 changes: 6 additions & 3 deletions ReCaptchaContact/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ReCaptchaContact"/>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ReCaptchaContact">
<sequence>
<module name="Magento_ReCaptchaUi"/>
</sequence>
</module>
</config>
8 changes: 3 additions & 5 deletions ReCaptchaContact/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
declare(strict_types=1);

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magento_ReCaptchaContact',
__DIR__
);
use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_ReCaptchaContact', __DIR__);
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="form.additional.info">
<block class="Magento\ReCaptchaUi\Block\ReCaptcha"
Expand Down
11 changes: 8 additions & 3 deletions ReCaptchaCustomer/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ReCaptchaCustomer"/>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ReCaptchaCustomer">
<sequence>
<module name="Magento_Customer"/>
<module name="Magento_ReCaptchaUi"/>
<module name="Magento_ReCaptchaValidationApi"/>
</sequence>
</module>
</config>
6 changes: 1 addition & 5 deletions ReCaptchaFrontendUi/Model/CaptchaTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public function __construct(
*/
public function getCaptchaTypeFor(string $key): ?string
{
$type = $this->scopeConfig->getValue(
self::XML_PATH_TYPE_FOR . $key,
ScopeInterface::SCOPE_WEBSITE
);
return $type;
return $this->scopeConfig->getValue(self::XML_PATH_TYPE_FOR . $key, ScopeInterface::SCOPE_WEBSITE);
}
}
10 changes: 2 additions & 8 deletions ReCaptchaFrontendUi/Model/ErrorMessageConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,14 @@ public function __construct(
*/
public function getTechnicalFailureMessage(): string
{
return $this->scopeConfig->getValue(
self::XML_PATH_TECHNICAL,
ScopeInterface::SCOPE_STORE
);
return $this->scopeConfig->getValue(self::XML_PATH_TECHNICAL, ScopeInterface::SCOPE_STORE);
}

/**
* @inheritdoc
*/
public function getValidationFailureMessage(): string
{
return $this->scopeConfig->getValue(
self::XML_PATH_VALIDATION,
ScopeInterface::SCOPE_STORE
);
return $this->scopeConfig->getValue(self::XML_PATH_VALIDATION, ScopeInterface::SCOPE_STORE);
}
}
34 changes: 0 additions & 34 deletions ReCaptchaFrontendUi/Plugin/ExcludeFromMinification.php

This file was deleted.

4 changes: 0 additions & 4 deletions ReCaptchaFrontendUi/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@
type="Magento\ReCaptchaFrontendUi\Model\CaptchaTypeResolver"/>
<preference for="Magento\ReCaptchaUi\Model\ErrorMessageConfigInterface"
type="Magento\ReCaptchaFrontendUi\Model\ErrorMessageConfig"/>
<type name="Magento\Framework\View\Asset\Minification">
<plugin name="exclude-recaptcha-from-minification"
type="Magento\ReCaptchaFrontendUi\Plugin\ExcludeFromMinification"/>
</type>
</config>
Loading

0 comments on commit f5ff14c

Please sign in to comment.