Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Puzzle Endpoint filed in SiteConfig to checkbox #32

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'] ?? false;
$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
2 changes: 1 addition & 1 deletion Tests/Unit/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function configurationIsBuiltCorrectly(): void
$configuration = new Configuration();
self::assertEquals('12345', $configuration->getSiteKey());
self::assertEquals('ABCDEF', $configuration->getSiteSecretKey());
self::assertEquals('', $configuration->getPuzzleEndpoint());
self::assertFalse($configuration->useEuPuzzleEndpoint());
self::assertEquals('https://verify,https://verify2', $configuration->getVerifyUrl());
self::assertEquals('https://verify', $configuration->getFirstVerifyUrl());
self::assertTrue($configuration->isEnabled());
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/ViewHelpers/ConfigurationViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function viewHelperReturnsProperConfiguration()
self::assertSame([
'siteKey' => '1234',
'verifyUrl' => 'https://verify,https://verify2',
'puzzleEndpoint' => '',
'useEuPuzzleEndpoint' => false,
'jsPath' => 'EXT:friendlycaptcha_official/Resources/Public/JavaScript/lib/[email protected]',
'enabled' => true,
], $configurationViewHelper->render());
Expand Down