Skip to content

Commit 74e3661

Browse files
authored
Merge pull request #661 from in2code-de/feature/validate-missing-captcha
Related ticket: https://projekte.in2code.de/issues/56659
2 parents 002112d + 64e756a commit 74e3661

5 files changed

Lines changed: 29 additions & 0 deletions

File tree

Classes/Controller/AbstractController.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use TYPO3\CMS\Backend\Utility\BackendUtility as BackendUtilityCore;
2626
use TYPO3\CMS\Core\Database\ConnectionPool;
2727
use TYPO3\CMS\Core\Http\ApplicationType;
28+
use TYPO3\CMS\Core\Http\PropagateResponseException;
2829
use TYPO3\CMS\Core\Http\RedirectResponse;
2930
use TYPO3\CMS\Core\Http\UploadedFile;
3031
use \TYPO3\CMS\Core\Resource\Enum\DuplicationBehavior;
@@ -655,4 +656,25 @@ public function sendCreateUserConfirmationMailFromBackend(User $user): void
655656
$this->request
656657
);
657658
}
659+
660+
protected function validateMissingCaptcha(string $redirectAction): void
661+
{
662+
if ($this->isCaptchaEnabled() && $this->request->getAttribute('extbase')->getArgument('captcha') === '') {
663+
$this->addFlashMessage(
664+
LocalizationUtility::translate('validationErrorCaptcha'),
665+
'',
666+
ContextualFeedbackSeverity::ERROR
667+
);
668+
throw new PropagateResponseException($this->redirect($redirectAction), 12398019239);
669+
}
670+
}
671+
672+
protected function isCaptchaEnabled(): bool {
673+
$extbaseAttribute = $this->request->getAttribute('extbase');
674+
$controllerName = strtolower($extbaseAttribute->getControllerName());
675+
676+
return $extbaseAttribute->hasArgument('captcha') &&
677+
$this->config[$controllerName . '.']['validation.']['captcha.']['captcha'] == true &&
678+
ExtensionManagementUtility::isLoaded('sr_freecap');
679+
}
658680
}

Classes/Controller/EditController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function editAction(): ResponseInterface
5454
#[Validate(['validator' => CaptchaValidator::class, 'param' => 'captcha'])]
5555
public function updateAction(User $user, ?string $captcha = null)
5656
{
57+
$this->validateMissingCaptcha('edit');
58+
5759
$currentUser = UserUtility::getCurrentUser();
5860
$userValues = $this->request->getArgument('user') ?? [];
5961
$token = $this->request->getArgument('token') ?? null;

Classes/Controller/InvitationController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public function newAction(): ResponseInterface
5959
#[Validate(['validator' => CaptchaValidator::class, 'param' => 'captcha'])]
6060
public function createAction(User $user, ?string $captcha = null): ResponseInterface
6161
{
62+
$this->validateMissingCaptcha('new');
63+
6264
if ($this->ratelimiterService->isLimited()) {
6365
$this->addFlashMessage(
6466
LocalizationUtility::translate('ratelimiter_too_many_attempts'),

Classes/Controller/NewController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function newAction(): ResponseInterface
6666
#[Validate(['validator' => CaptchaValidator::class, 'param' => 'captcha'])]
6767
public function createAction(User $user, ?string $captcha = null): ResponseInterface
6868
{
69+
$this->validateMissingCaptcha('new');
70+
6971
if ($this->ratelimiterService->isLimited()) {
7072
$this->addFlashMessage(
7173
LocalizationUtility::translate('ratelimiter_too_many_attempts'),

Classes/Domain/Validator/ClientsideValidator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ public function validateField(string $pluginName = 'tx_femanager_new'): bool
272272
$wordRepository = GeneralUtility::makeInstance(
273273
WordRepository::class
274274
);
275+
$wordRepository->setRequest($this->request ?? $GLOBALS["TYPO3_REQUEST"]);
275276
$wordObject = $wordRepository->getWord();
276277
$wordHash = $wordObject->getWordHash();
277278
$userVal = md5(strtolower(mb_convert_encoding($this->getValue(), 'ISO-8859-1')));

0 commit comments

Comments
 (0)