Skip to content

Commit

Permalink
Merge pull request #4 from koehnlein/feature/skip-dev-validation
Browse files Browse the repository at this point in the history
Allow to skip validation in development context
  • Loading branch information
georgringer authored Dec 4, 2023
2 parents e5a44b3 + d33705e commit 5b14d9e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Classes/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace StudioMitte\FriendlyCaptcha;

use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand All @@ -16,6 +17,7 @@ class Configuration
protected string $puzzleUrl = '';
protected string $verifyUrl = '';
protected string $jsPath = '';
protected bool $skipDevValidation = false;

public function __construct(Site $site = null)
{
Expand All @@ -31,6 +33,7 @@ public function __construct(Site $site = null)
$this->puzzleUrl = trim($siteConfiguration['friendlycaptcha_puzzle_url'] ?? '');
$this->verifyUrl = trim($siteConfiguration['friendlycaptcha_verify_url'] ?? '');
$this->jsPath = trim($siteConfiguration['friendlycaptcha_js_path'] ?? '');
$this->skipDevValidation = (bool)($siteConfiguration['friendlycaptcha_skip_dev_validation'] ?? false);
}

public function isEnabled(): bool
Expand Down Expand Up @@ -68,4 +71,9 @@ public function getJsPath(): string
{
return $this->jsPath ?: self::DEFAULT_JS_PATH;
}

public function hasSkipDevValidation(): bool
{
return Environment::getContext()->isDevelopment() && $this->skipDevValidation;
}
}
4 changes: 4 additions & 0 deletions Classes/Service/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function __construct(

public function verify(string $solution = ''): bool
{
if ($this->configuration->hasSkipDevValidation()) {
return true;
}

$solution = $solution ?: $this->getSolutionFromRequest();
if (!$solution || !$this->configuration->isEnabled()) {
return false;
Expand Down
9 changes: 8 additions & 1 deletion Configuration/SiteConfiguration/Overrides/sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ static function () {
'default' => \StudioMitte\FriendlyCaptcha\Configuration::DEFAULT_JS_PATH,
],
];
$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] .= ',--div--;' . $lll . 'site.configuration.tab, friendlycaptcha_site_key,friendlycaptcha_secret_key,friendlycaptcha_puzzle_url,friendlycaptcha_verify_url,friendlycaptcha_js_path,';
$GLOBALS['SiteConfiguration']['site']['columns']['friendlycaptcha_skip_dev_validation'] = [
'label' => $lll . 'site.configuration.skip_dev_validation',
'description' => $lll . 'site.configuration.skip_dev_validation.description',
'config' => [
'type' => 'check',
],
];
$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] .= ',--div--;' . $lll . 'site.configuration.tab, friendlycaptcha_site_key,friendlycaptcha_secret_key,friendlycaptcha_puzzle_url,friendlycaptcha_verify_url,friendlycaptcha_js_path,friendlycaptcha_skip_dev_validation,';
}
);
6 changes: 6 additions & 0 deletions Resources/Private/Language/Configuration.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<trans-unit id="site.configuration.js_path">
<source>JavaScript Path</source>
</trans-unit>
<trans-unit id="site.configuration.skip_dev_validation">
<source>Skip validation in Development context</source>
</trans-unit>
<trans-unit id="site.configuration.skip_dev_validation.description">
<source>Must never be used on your live website. Only possible in Development context. Can be useful for automated form testing.</source>
</trans-unit>
</body>
</file>
</xliff>
1 change: 1 addition & 0 deletions Tests/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static function setupRequest(string $siteKey = '1234', string $secretKey
'friendlycaptcha_secret_key' => $secretKey,
'friendlycaptcha_site_key' => $siteKey,
'friendlycaptcha_verify_url' => 'https://verify,https://verify2',
'friendlycaptcha_skip_dev_validation' => false,
]);
$GLOBALS['TYPO3_REQUEST'] = (new ServerRequest())
->withAttribute('site', $site)
Expand Down

0 comments on commit 5b14d9e

Please sign in to comment.