Skip to content

Commit

Permalink
Merge pull request #1 from Pixel-Open/100.1.2
Browse files Browse the repository at this point in the history
100.1.2
  • Loading branch information
magentix authored Apr 13, 2023
2 parents 04aeae4 + 21c5450 commit f789ca4
Show file tree
Hide file tree
Showing 25 changed files with 81 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Block/Turnstile.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Block/Turnstile/Config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 100.1.2

- Config path updated
- CSP Whitelist added
- Fix form validator when Turnstile is disabled

## 100.1.1

- Fix review data persistor
Expand Down
12 changes: 6 additions & 6 deletions Helper/Config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -14,11 +14,11 @@

class Config extends AbstractHelper
{
public const TURNSTILE_CONFIG_PATH_ENABLED = 'pixel_open/cloudflare_turnstile/enabled';
public const TURNSTILE_CONFIG_PATH_SECRET_KEY = 'pixel_open/cloudflare_turnstile/secret_key';
public const TURNSTILE_CONFIG_PATH_SITEKEY = 'pixel_open/cloudflare_turnstile/sitekey';
public const TURNSTILE_CONFIG_PATH_THEME = 'pixel_open/cloudflare_turnstile/theme';
public const TURNSTILE_CONFIG_PATH_FORMS = 'pixel_open/cloudflare_turnstile/forms';
public const TURNSTILE_CONFIG_PATH_ENABLED = 'pixel_open_cloudflare_turnstile/settings/enabled';
public const TURNSTILE_CONFIG_PATH_SECRET_KEY = 'pixel_open_cloudflare_turnstile/settings/secret_key';
public const TURNSTILE_CONFIG_PATH_SITEKEY = 'pixel_open_cloudflare_turnstile/settings/sitekey';
public const TURNSTILE_CONFIG_PATH_THEME = 'pixel_open_cloudflare_turnstile/settings/theme';
public const TURNSTILE_CONFIG_PATH_FORMS = 'pixel_open_cloudflare_turnstile/settings/forms';

/**
* Is Turnstile enabled
Expand Down
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Pixel Développement
Copyright (c) 2023 Pixel Développement

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/Forms.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Model/Config/Source/Theme.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Model/Turnstile/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Model/Validator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
13 changes: 11 additions & 2 deletions Observer/Validate.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down Expand Up @@ -28,6 +28,7 @@
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Session\Generic;
use Magento\Review\Controller\Product\Post as ReviewPost;
use PixelOpen\CloudflareTurnstile\Helper\Config;
use PixelOpen\CloudflareTurnstile\Model\Config\Source\Forms;
use PixelOpen\CloudflareTurnstile\Model\Validator;

Expand All @@ -47,6 +48,8 @@ class Validate implements ObserverInterface

protected Json $json;

protected Config $config;

/**
* @param ManagerInterface $messageManager
* @param Response $response
Expand All @@ -55,6 +58,7 @@ class Validate implements ObserverInterface
* @param Generic $reviewSession
* @param Validator $validator
* @param Json $json
* @param Config $config
*/
public function __construct(
ManagerInterface $messageManager,
Expand All @@ -63,7 +67,8 @@ public function __construct(
CustomerSession $customerSession,
Generic $reviewSession,
Validator $validator,
Json $json
Json $json,
Config $config
) {
$this->messageManager = $messageManager;
$this->response = $response;
Expand All @@ -72,6 +77,7 @@ public function __construct(
$this->reviewSession = $reviewSession;
$this->validator = $validator;
$this->json = $json;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -130,6 +136,9 @@ public function getCfResponse(Request $request, ActionInterface $action): ?strin
*/
public function canValidate(Request $request, ActionInterface $action): bool
{
if (!$this->config->isEnabled()) {
return false;
}
if (!$request->isPost()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"magento/framework": "*"
},
"type": "magento2-module",
"version": "100.1.1",
"version": "100.1.2",
"autoload": {
"files": [
"registration.php"
Expand Down
4 changes: 2 additions & 2 deletions etc/acl.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -14,7 +14,7 @@
<resource id="Magento_Backend::stores">
<resource id="Magento_Backend::stores_settings">
<resource id="Magento_Config::config">
<resource id="Pixel_CloudflareTurnstile::settings" title="Cloudflare Turnstile" translate="title" />
<resource id="PixelOpen_CloudflareTurnstile::settings" title="Cloudflare Turnstile" translate="title" />
</resource>
</resource>
</resource>
Expand Down
8 changes: 4 additions & 4 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="pixel_open" translate="label" type="text" sortOrder="900" showInDefault="1" showInWebsite="1" showInStore="1">
<section id="pixel_open_cloudflare_turnstile" translate="label" type="text" sortOrder="900" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Cloudflare Turnstile</label>
<tab>customer</tab>
<resource>Pixel_CloudflareTurnstile::settings</resource>
<group id="cloudflare_turnstile" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<resource>PixelOpen_CloudflareTurnstile::settings</resource>
<group id="settings" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Settings</label>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
Expand Down
10 changes: 5 additions & 5 deletions etc/config.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<pixel_open>
<cloudflare_turnstile>
<pixel_open_cloudflare_turnstile>
<settings>
<enabled>0</enabled>
<theme>light</theme>
</cloudflare_turnstile>
</pixel_open>
</settings>
</pixel_open_cloudflare_turnstile>
</default>
</config>
23 changes: 23 additions & 0 deletions etc/csp_whitelist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-->
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
<policies>
<policy id="frame-src">
<values>
<value id="cloudflare_turnstile" type="host">challenges.cloudflare.com</value>
</values>
</policy>
<policy id="script-src">
<values>
<value id="cloudflare_turnstile" type="host">challenges.cloudflare.com</value>
</values>
</policy>
</policies>
</csp_whitelist>
2 changes: 1 addition & 1 deletion etc/frontend/di.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion etc/frontend/events.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/layout/catalog_product_view.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -10,7 +10,7 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="product.review.form.fields.before">
<block name="pixel.open.cloudflare.turnstile.review" class="PixelOpen\CloudflareTurnstile\Block\Turnstile" ifconfig="pixel_open/cloudflare_turnstile/enabled">
<block name="pixel.open.cloudflare.turnstile.review" class="PixelOpen\CloudflareTurnstile\Block\Turnstile" ifconfig="pixel_open_cloudflare_turnstile/settings/enabled">
<action method="setAction">
<argument name="action" xsi:type="string">review</argument>
</action>
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/layout/contact_index_index.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -10,7 +10,7 @@
<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 name="pixel.open.cloudflare.turnstile.contact" class="PixelOpen\CloudflareTurnstile\Block\Turnstile" ifconfig="pixel_open/cloudflare_turnstile/enabled">
<block name="pixel.open.cloudflare.turnstile.contact" class="PixelOpen\CloudflareTurnstile\Block\Turnstile" ifconfig="pixel_open_cloudflare_turnstile/settings/enabled">
<action method="setAction">
<argument name="action" xsi:type="string">contact</argument>
</action>
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/layout/customer_account_create.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -10,7 +10,7 @@
<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 name="pixel.open.cloudflare.turnstile.register" class="PixelOpen\CloudflareTurnstile\Block\Turnstile" ifconfig="pixel_open/cloudflare_turnstile/enabled">
<block name="pixel.open.cloudflare.turnstile.register" class="PixelOpen\CloudflareTurnstile\Block\Turnstile" ifconfig="pixel_open_cloudflare_turnstile/settings/enabled">
<action method="setAction">
<argument name="action" xsi:type="string">register</argument>
</action>
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/layout/customer_account_forgotpassword.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -10,7 +10,7 @@
<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 name="pixel.open.cloudflare.turnstile.password" class="PixelOpen\CloudflareTurnstile\Block\Turnstile" ifconfig="pixel_open/cloudflare_turnstile/enabled">
<block name="pixel.open.cloudflare.turnstile.password" class="PixelOpen\CloudflareTurnstile\Block\Turnstile" ifconfig="pixel_open_cloudflare_turnstile/settings/enabled">
<action method="setAction">
<argument name="action" xsi:type="string">password</argument>
</action>
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/layout/customer_account_login.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -10,7 +10,7 @@
<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 name="pixel.open.cloudflare.turnstile.login" class="PixelOpen\CloudflareTurnstile\Block\Turnstile" ifconfig="pixel_open/cloudflare_turnstile/enabled">
<block name="pixel.open.cloudflare.turnstile.login" class="PixelOpen\CloudflareTurnstile\Block\Turnstile" ifconfig="pixel_open_cloudflare_turnstile/settings/enabled">
<action method="setAction">
<argument name="action" xsi:type="string">login</argument>
</action>
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,7 +13,7 @@
</head>
<body>
<referenceContainer name="before.body.end">
<block class="PixelOpen\CloudflareTurnstile\Block\Turnstile\Config" template="PixelOpen_CloudflareTurnstile::turnstile/config.phtml" ifconfig="pixel_open/cloudflare_turnstile/enabled" />
<block class="PixelOpen\CloudflareTurnstile\Block\Turnstile\Config" template="PixelOpen_CloudflareTurnstile::turnstile/config.phtml" ifconfig="pixel_open_cloudflare_turnstile/settings/enabled" />
</referenceContainer>
<referenceBlock name="authentication-popup">
<arguments>
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/web/js/view/turnstile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2022 Pixel Développement
* Copyright (C) 2023 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down

0 comments on commit f789ca4

Please sign in to comment.