feat(altcha): add altcha validation layer to login
Some checks are pending
Cadoles/hydra-sql/pipeline/pr-develop Build started...

This commit is contained in:
2025-03-24 17:20:17 +01:00
parent 1cb5ae6bc3
commit 12523398f6
51 changed files with 2417 additions and 1137 deletions

View File

@ -0,0 +1,52 @@
<?php
namespace App\Altcha;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class AltchaValidator
{
public function __construct(
private readonly string $altchaHost,
private readonly string $altchaBaseUrl,
private readonly HttpClientInterface $httpClient,
private readonly TranslatorInterface $translator
) {
}
public function validate(FormEvent $formEvent): void
{
$form = $formEvent->getForm();
$data = $form->getData();
$response = $this->httpClient->request(
'POST',
$this->altchaHost.$this->altchaBaseUrl.'/verify',
[
'body' => json_encode($data),
'headers' => [
'Content-Type' => 'application/json',
],
],
);
if (Response::HTTP_OK !== $response->getStatusCode()) {
$form->addError(new FormError($this->translator->trans('altcha.validator.server_validation_error', [], 'form')));
return;
}
$content = $response->getContent();
$parsedResponse = json_decode($content);
if (true !== $parsedResponse->success) {
$form->addError(new FormError($this->translator->trans('altcha.validator.server_validation_error', [], 'form')));
return;
}
}
}