Skip to content

Commit f88df90

Browse files
committed
feat: upgrade to CaptchEtat V2
1 parent 9e6f776 commit f88df90

File tree

16 files changed

+181
-252
lines changed

16 files changed

+181
-252
lines changed

components/CaptchEtatBundle/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ CAPTCHETAT_OAUTH_URL="https://sandbox-oauth.piste.gouv.fr"
6565
CAPTCHETAT_OAUTH_CLIENT_ID=~
6666
CAPTCHETAT_OAUTH_CLIENT_SECRET=~
6767
CAPTCHETAT_TIMEOUT="2.5"
68-
CAPTCHETAT_TYPE=""
6968
```
7069

7170
Depending on if you use "sandbox" (default) or "production" environment, you might want to change the urls to :

components/CaptchEtatBundle/src/bundle/Controller/CaptchEtatController.php

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,16 @@
55
namespace AlmaviaCX\Bundle\CaptchEtatBundle\Controller;
66

77
use AlmaviaCX\Bundle\CaptchEtat\Api\Gateway;
8-
use AlmaviaCX\Bundle\CaptchEtat\Challenge\ChallengeGenerator;
98
use Symfony\Component\HttpFoundation\Request;
109
use Symfony\Component\HttpFoundation\Response;
1110
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
1211

1312
class CaptchEtatController
1413
{
15-
protected Gateway $gateway;
16-
protected ChallengeGenerator $challengeGenerator;
17-
1814
public function __construct(
19-
Gateway $gateway,
20-
ChallengeGenerator $challengeGenerator
15+
Gateway $gateway
2116
) {
2217
$this->gateway = $gateway;
23-
$this->challengeGenerator = $challengeGenerator;
2418
}
2519

2620
/**
@@ -31,34 +25,20 @@ public function apiSimpleCaptchaEndpointAction(Request $request): Response
3125
$get = $request->get('get');
3226
$tech = $request->get('t');
3327
$type = $request->get('c');
34-
$content = $this->gateway->getSimpleCaptchaEndpoint($get, null, $tech, $type);
28+
$content = $this->gateway->getSimpleCaptchaEndpoint($get, $tech, $type);
3529
$response = new Response($content);
36-
if ('script-include' === $get) {
37-
$response->headers->set('Content-Type', 'text/javascript');
38-
} elseif ('image' === $get) {
39-
$response->headers->set('Content-Disposition', $response->headers->makeDisposition(
40-
ResponseHeaderBag::DISPOSITION_INLINE,
41-
'captcha.png'
42-
));
43-
$response->headers->set('Content-Type', 'image/png');
44-
} elseif ('sound' === $get) {
30+
31+
if ('sound' === $get) {
4532
$response->headers->set('Content-Disposition', $response->headers->makeDisposition(
4633
ResponseHeaderBag::DISPOSITION_INLINE,
4734
'captcha-sound.wave'
4835
));
49-
$response->headers->set('Content-Type', 'audio/wave');
36+
$response->headers->set('Content-Type', 'audio/x-wav');
37+
} else {
38+
$response->headers->set('Content-Type', 'application/json');
5039
}
5140
$response->setPrivate();
5241

5342
return $response;
5443
}
55-
56-
public function getCaptcha(): Response
57-
{
58-
$challenge = ($this->challengeGenerator)();
59-
$response = new Response($challenge);
60-
$response->setPrivate();
61-
62-
return $response;
63-
}
6444
}

components/CaptchEtatBundle/src/bundle/Resources/config/default_settings.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ parameters:
1212
captchetat_oauth_client_secret: '%env(string:CAPTCHETAT_OAUTH_CLIENT_SECRET)%'
1313
captchetat_api_url: '%env(string:CAPTCHETAT_API_URL)%'
1414
captchetat_timeout: '%env(float:CAPTCHETAT_TIMEOUT)%'
15-
captchetat_type: '%env(string:CAPTCHETAT_TYPE)%'

components/CaptchEtatBundle/src/bundle/Resources/config/routes.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,3 @@ captchetat.endpoint:
22
path: /api/simple-captcha-endpoint
33
defaults:
44
_controller: 'AlmaviaCX\Bundle\CaptchEtatBundle\Controller\CaptchEtatController::apiSimpleCaptchaEndpointAction'
5-
6-
captchetat.html:
7-
path: /api/simple-captcha
8-
defaults:
9-
_controller: 'AlmaviaCX\Bundle\CaptchEtatBundle\Controller\CaptchEtatController::getCaptcha'

components/CaptchEtatBundle/src/bundle/Resources/config/services.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ services:
2020
$url: '%captchetat_api_url%'
2121
$timeout: '%captchetat_timeout%'
2222

23-
AlmaviaCX\Bundle\CaptchEtat\Challenge\ChallengeGenerator:
24-
arguments:
25-
$configResolver: '@Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface'
26-
$localeConverter: '@Ibexa\Core\MVC\Symfony\Locale\LocaleConverterInterface'
27-
$gateway: '@AlmaviaCX\Bundle\CaptchEtat\Api\Gateway'
28-
$translator: '@Symfony\Contracts\Translation\TranslatorInterface'
29-
$logger: '@AlmaviaCX\Bundle\CaptchEtat\Logger\CaptchEtatLogger'
30-
$captchetatType: '%captchetat_type%'
31-
3223
AlmaviaCX\Bundle\CaptchEtat\Challenge\ChallengeValidator:
3324
arguments:
3425
$gateway: '@AlmaviaCX\Bundle\CaptchEtat\Api\Gateway'
@@ -48,10 +39,16 @@ services:
4839
AlmaviaCX\Bundle\CaptchEtatBundle\Controller\CaptchEtatController:
4940
arguments:
5041
$gateway: '@AlmaviaCX\Bundle\CaptchEtat\Api\Gateway'
51-
$challengeGenerator: '@AlmaviaCX\Bundle\CaptchEtat\Challenge\ChallengeGenerator'
5242
tags:
5343
- controller.service_arguments
5444

45+
AlmaviaCX\Bundle\CaptchEtat\Twig\CaptchEtatExtension:
46+
arguments:
47+
$configResolver: '@Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface'
48+
$localeConverter: '@Ibexa\Core\MVC\Symfony\Locale\LocaleConverterInterface'
49+
tags:
50+
- { name: twig.extension }
51+
5552
# AlmaviaCX\Bundle\CaptchEtat\FormBuilder\FieldType\Field\Mapper\ButtonFieldMapperDecorator:
5653
# decorates: Ibexa\FormBuilder\FieldType\Field\Mapper\ButtonFieldMapper
5754
# arguments:

components/CaptchEtatBundle/src/bundle/Resources/public/js/captchetat-v2-widget.js

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)