Skip to content

Commit

Permalink
Change Puzzle Endpoint filed in SiteConfig to checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
80Quattro committed Dec 13, 2024
1 parent 945c9f8 commit 89fb746
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Classes/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Configuration

protected string $siteKey = '';
protected string $siteSecretKey = '';
protected string $puzzleEndpoint = '';
protected bool $useEuPuzzleEndpoint = false;
protected string $verifyUrl = '';
protected string $jsPath = '';
protected bool $skipDevValidation = false;
Expand All @@ -31,7 +31,7 @@ public function __construct(Site $site = null)
$siteConfiguration = $site->getConfiguration();
$this->siteKey = trim($siteConfiguration['friendlycaptcha_site_key'] ?? '');
$this->siteSecretKey = trim($siteConfiguration['friendlycaptcha_secret_key'] ?? '');
$this->puzzleEndpoint = trim($siteConfiguration['friendlycaptcha_puzzle_endpoint'] ?? '');
$this->useEuPuzzleEndpoint = $siteConfiguration['friendlycaptcha_use_eu_puzzle_endpoint'];
$this->verifyUrl = trim($siteConfiguration['friendlycaptcha_verify_url'] ?? '');
$this->jsPath = trim($siteConfiguration['friendlycaptcha_js_path'] ?? '');
$this->skipDevValidation = (bool)($siteConfiguration['friendlycaptcha_skip_dev_validation'] ?? false);
Expand All @@ -52,9 +52,9 @@ public function getSiteSecretKey(): string
return $this->siteSecretKey;
}

public function getPuzzleEndpoint(): string
public function useEuPuzzleEndpoint(): bool
{
return $this->puzzleEndpoint;
return $this->useEuPuzzleEndpoint;
}

public function getVerifyUrl(): string
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/ConfigurationViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function render()
return [
'siteKey' => $configuration->getSiteKey(),
'verifyUrl' => $configuration->getVerifyUrl(),
'puzzleEndpoint' => $configuration->getPuzzleEndpoint(),
'useEuPuzzleEndpoint' => $configuration->useEuPuzzleEndpoint(),
'jsPath' => $configuration->getJsPath(),
'enabled' => $configuration->isEnabled(),
];
Expand Down
8 changes: 3 additions & 5 deletions Configuration/SiteConfiguration/Overrides/sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ static function () {
'placeholder' => 'A16UE6NICBMVQKG1I1BFMLBD56K53D3CS0L5N00AJNBT1R41P8O7N1KFMH',
],
];
$GLOBALS['SiteConfiguration']['site']['columns']['friendlycaptcha_puzzle_endpoint'] = [
$GLOBALS['SiteConfiguration']['site']['columns']['friendlycaptcha_use_eu_puzzle_endpoint'] = [
'label' => $lll . 'site.configuration.puzzle_endpoint',
'config' => [
'type' => 'input',
'placeholder' => 'eu',
'default' => '',
'type' => 'check',
],
];
$GLOBALS['SiteConfiguration']['site']['columns']['friendlycaptcha_verify_url'] = [
Expand All @@ -48,6 +46,6 @@ static function () {
'type' => 'check',
],
];
$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] .= ',--div--;' . $lll . 'site.configuration.tab, friendlycaptcha_site_key,friendlycaptcha_secret_key,friendlycaptcha_puzzle_endpoint,friendlycaptcha_verify_url,friendlycaptcha_js_path,friendlycaptcha_skip_dev_validation,';
$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] .= ',--div--;' . $lll . 'site.configuration.tab, friendlycaptcha_site_key,friendlycaptcha_secret_key,friendlycaptcha_use_eu_puzzle_endpoint,friendlycaptcha_verify_url,friendlycaptcha_js_path,friendlycaptcha_skip_dev_validation,';
}
);
3 changes: 3 additions & 0 deletions Documentation/Configuration/Integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ A new tab **Friendly Captcha** is available which includes all configuration opt
This is described in the :ref:`using` section!


By default, the global endpoint `https://global.frcapi.com/api/v2/captcha/siteverify` is used.
If you prefer to use the EU endpoint, enter `https://eu.frcapi.com/api/v2/captcha/siteverify` in `Verify URL` field and ensure that the `Use EU Puzzle Endpoint` option is checked.

Working with automated tests
============================
If you are using automated tests you might want to skip the captcha.
Expand Down
Binary file modified Documentation/Images/configuration_site.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Documentation/Using/Custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The puzzle needs to be integrated into the form. This can be done like this in y
<f:if condition="{captchaConfiguration.enabled}">
<f:then>
<f:asset.script defer="1" async="1" identifier="friendlycaptcha" src="{captchaConfiguration.jsPath}" />
<div class="frc-captcha" data-sitekey="{captchaConfiguration.siteKey}" data-lang="{captchaConfiguration.languageIsoCode}" data-puzzle-endpoint="{captchaConfiguration.puzzleUrl}"></div>
<div class="frc-captcha" data-sitekey="{captchaConfiguration.siteKey}" {f:if(condition: '{captchaConfiguration.useEuPuzzleEndpoint}', then: 'data-api-endpoint="eu"')}></div>
</f:then>
<f:else>
<p>{f:translate(key:'LLL:EXT:friendlycaptcha_official/Resources/Private/Language/locallang.xlf:configuration_missing')}</p>
Expand Down
2 changes: 1 addition & 1 deletion Documentation/V2_Migration/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ If you’re currently using an earlier version of the plugin with **Friendly Cap
* Enable **V2** in yout Application in the Panel at https://friendlycaptcha.com/
* Install the newest version of the plugin (min v1.0)
* In TYPO3 backend, go to the *Site Management*/*Sites* module and switch to the **FriendlyCaptcha** tab. You need to change the URLs
**Puzzle Endpoint** - save empty or `eu` if you want to use the EU Endpoint
**Puzzle Endpoint** - check it if you want to use the EU Endpoint
**Verify URL** - `https://global.frcapi.com/api/v2/captcha/siteverify` or `https://eu.frcapi.com/api/v2/captcha/siteverify` if you prefer to use EU endpoint
**JavaScript Path** - `EXT:friendlycaptcha_official/Resources/Public/JavaScript/lib/[email protected]`
2 changes: 1 addition & 1 deletion Resources/Private/Form/Partials/Friendlycaptcha.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
value="1"
additionalAttributes="{formvh:translateElementProperty(element: element, property: 'fluidAdditionalAttributes')}"
/>
<div class="frc-captcha" data-sitekey="{captchaConfiguration.siteKey}" {f:if(condition: '{captchaConfiguration.puzzleEndpoint}', then: 'data-api-endpoint="{captchaConfiguration.puzzleEndpoint}"')}></div>
<div class="frc-captcha" data-sitekey="{captchaConfiguration.siteKey}" {f:if(condition: '{captchaConfiguration.useEuPuzzleEndpoint}', then: 'data-api-endpoint="eu"')}></div>
</f:render>
</f:then>
<f:else>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Language/Configuration.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<source>Verify URL</source>
</trans-unit>
<trans-unit id="site.configuration.puzzle_endpoint">
<source>Puzzle Endpoint</source>
<source>Use EU Puzzle Endpoint</source>
</trans-unit>
<trans-unit id="site.configuration.js_path">
<source>JavaScript Path</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<f:if condition="{captchaConfiguration.enabled}">
<f:then>
<f:asset.script defer="1" async="1" identifier="friendlycaptcha" src="{captchaConfiguration.jsPath}" />
<div class="frc-captcha" data-sitekey="{captchaConfiguration.siteKey}" {f:if(condition: '{captchaConfiguration.puzzleEndpoint}', then: 'data-api-endpoint="{captchaConfiguration.puzzleEndpoint}"')}></div>
<div class="frc-captcha" data-sitekey="{captchaConfiguration.siteKey}" {f:if(condition: '{captchaConfiguration.useEuPuzzleEndpoint}', then: 'data-api-endpoint="eu"')}></div>
</f:then>
<f:else>
<p>{f:translate(key:'LLL:EXT:friendlycaptcha_official/Resources/Private/Language/locallang.xlf:configuration_missing')}</p>
Expand Down

0 comments on commit 89fb746

Please sign in to comment.