From 74f9767cf49ebd654d65090f703051ff5c7503b7 Mon Sep 17 00:00:00 2001 From: nourmkaouar Date: Mon, 6 Jan 2025 17:47:49 +0100 Subject: [PATCH] [TASK] add captcha validator --- Classes/Controller/ActionController.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Classes/Controller/ActionController.php b/Classes/Controller/ActionController.php index 4b05253..5aa04e7 100644 --- a/Classes/Controller/ActionController.php +++ b/Classes/Controller/ActionController.php @@ -27,6 +27,7 @@ use TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationBuilder; use TYPO3\CMS\Extbase\Service\EnvironmentService; use TYPO3\CMS\Extbase\Service\ExtensionService; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; +use Blueways\BwCaptcha\Validation\Validator\CaptchaValidator; class ActionController extends BaseController { @@ -835,4 +836,26 @@ class ActionController extends BaseController ); } } + /** **/ + protected function valideCaptcha($captchaId, $value + ) { + $cacheIdentifier = $GLOBALS['TSFE']->fe_user->getKey('ses', $captchaId); + + if (!$cacheIdentifier) { + $this->addValidationError( + 'captcha', + 'validator.notvalid' + ); + } + // get captcha secret from cache and compare + $cache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('bwcaptcha'); + $phrase = $cache->get($cacheIdentifier); + if ($phrase && $phrase === $value) { + return true; + } + $this->addValidationError( + 'captcha', + 'validator.notvalid' + ); + } }