[BUGFIX] Fix Captcha Validator
This commit is contained in:
parent
f52f1c2c35
commit
a329a52505
@ -28,6 +28,7 @@ use TYPO3\CMS\Extbase\Service\EnvironmentService;
|
|||||||
use TYPO3\CMS\Extbase\Service\ExtensionService;
|
use TYPO3\CMS\Extbase\Service\ExtensionService;
|
||||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||||
use Blueways\BwCaptcha\Validation\Validator\CaptchaValidator;
|
use Blueways\BwCaptcha\Validation\Validator\CaptchaValidator;
|
||||||
|
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
|
||||||
|
|
||||||
class ActionController extends BaseController
|
class ActionController extends BaseController
|
||||||
{
|
{
|
||||||
@ -839,23 +840,40 @@ class ActionController extends BaseController
|
|||||||
/** **/
|
/** **/
|
||||||
protected function valideCaptcha($captchaId, $value
|
protected function valideCaptcha($captchaId, $value
|
||||||
) {
|
) {
|
||||||
$cacheIdentifier = $GLOBALS['TSFE']->fe_user->getKey('ses', $captchaId);
|
$captchaPhrases = $this->getFeUser()->getKey('ses', 'captchaPhrases');
|
||||||
|
if (!$captchaPhrases || !is_array($captchaPhrases) || !is_string($value)) {
|
||||||
if (!$cacheIdentifier) {
|
|
||||||
$this->addValidationError(
|
$this->addValidationError(
|
||||||
'captcha',
|
'captcha',
|
||||||
'validator.notvalid'
|
'validator.notvalid'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// get captcha secret from cache and compare
|
// get captcha secret from cache and compare
|
||||||
$cache = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('bwcaptcha');
|
$time = time();
|
||||||
$phrase = $cache->get($cacheIdentifier);
|
$captchaPhrases = array_filter(
|
||||||
if ($phrase && $phrase === $value) {
|
$captchaPhrases,
|
||||||
|
function ($captchaLifetime) use ($time) {
|
||||||
|
return $captchaLifetime > $time;
|
||||||
|
},
|
||||||
|
ARRAY_FILTER_USE_KEY
|
||||||
|
);
|
||||||
|
foreach ($captchaPhrases as $lifetime => $captchaPhrase) {
|
||||||
|
$isValid = !empty($captchaPhrase) && $captchaPhrase === $value;
|
||||||
|
if ($isValid) {
|
||||||
|
// remove solved captcha
|
||||||
|
unset($captchaPhrases[$lifetime]);
|
||||||
|
$this->getFeUser()->setKey('ses', 'captchaPhrases', $captchaPhrases);
|
||||||
|
$this->getFeUser()->storeSessionData();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$this->addValidationError(
|
$this->addValidationError(
|
||||||
'captcha',
|
'captcha',
|
||||||
'validator.notvalid'
|
'validator.notvalid'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getFeUser(): FrontendUserAuthentication
|
||||||
|
{
|
||||||
|
return $GLOBALS['TSFE']->fe_user;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,17 +30,7 @@ return [
|
|||||||
'exclude' => true,
|
'exclude' => true,
|
||||||
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
|
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
|
||||||
'config' => [
|
'config' => [
|
||||||
'type' => 'select',
|
'type' => 'language',
|
||||||
'renderType' => 'selectSingle',
|
|
||||||
'special' => 'languages',
|
|
||||||
'items' => [
|
|
||||||
[
|
|
||||||
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages',
|
|
||||||
-1,
|
|
||||||
'flags-multiple'
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'default' => 0,
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'l10n_parent' => [
|
'l10n_parent' => [
|
||||||
|
@ -30,17 +30,7 @@ return [
|
|||||||
'exclude' => true,
|
'exclude' => true,
|
||||||
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
|
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
|
||||||
'config' => [
|
'config' => [
|
||||||
'type' => 'select',
|
'type' => 'language',
|
||||||
'renderType' => 'selectSingle',
|
|
||||||
'special' => 'languages',
|
|
||||||
'items' => [
|
|
||||||
[
|
|
||||||
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages',
|
|
||||||
-1,
|
|
||||||
'flags-multiple'
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'default' => 0,
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'l10n_parent' => [
|
'l10n_parent' => [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user