Skip to content

Commit 000bf6b

Browse files
author
adil.slassi
committed
add captcha type env parametre
1 parent 9763352 commit 000bf6b

File tree

7 files changed

+36
-3
lines changed

7 files changed

+36
-3
lines changed

components/CaptchEtatBundle/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ 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=""
6869
```
6970

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ 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/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ services:
2727
$gateway: '@AlmaviaCX\Bundle\CaptchEtat\Api\Gateway'
2828
$translator: '@Symfony\Contracts\Translation\TranslatorInterface'
2929
$logger: '@AlmaviaCX\Bundle\CaptchEtat\Logger\CaptchEtatLogger'
30+
$captchetatType: '%captchetat_type%'
3031

3132
AlmaviaCX\Bundle\CaptchEtat\Challenge\ChallengeValidator:
3233
arguments:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// unminifyed version js https://static.piste.gouv.fr/captchEtat/libraries/captchetat-js-1.0.0.tgz
12
!(function () {
23
"use strict";
34
let e, t, n, a, c;

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,40 @@ export const captchaEtat = (function () {
5656
}).then((data) => {
5757
console.log('data ::', data);
5858
//__________________ add img tag
59-
const parsedData = JSON.parse(data);
59+
const parsedData = JSON.parse(html);
6060
const imageBase64 = parsedData.imageb64;
6161
const imageId = parsedData.uuid;
6262
const img = document.createElement('img');
6363
img.src = imageBase64;
6464
img.id = imageId;
6565
img.classList = "captch-etat-v2";
66+
let parent = htmlContainer
6667
htmlContainer.appendChild(img);
6768
console.log('okkk ::');
6869
//__________________ add img tag
70+
71+
72+
const tmp = document.createElement('div');
73+
tmp.innerHTML = html;
74+
addLinksToHead(tmp);
75+
addScriptsToHead(tmp);
76+
const originalIdInput = tmp.querySelector('[name^="BDC_VCID"]');
77+
idInput.value = originalIdInput.value;
78+
79+
const tmpRoot = tmp.children.item(0);
80+
tmpRoot.removeAttribute('id');
81+
tmpRoot.classList.add('captcha-html');
82+
83+
htmlContainer.prepend(tmpRoot);
84+
85+
const soundLink = widget.querySelector('.BDC_SoundLink');
86+
const answerInput = widget.querySelector('.captcha-input input[type="text"]');
87+
soundLink.addEventListener('click', function (e) {
88+
if (answerInput) {
89+
answer.removeAttribute('disabled');
90+
answerInput.focus();
91+
}
92+
});
6993
});
7094
}
7195
}

components/CaptchEtatBundle/src/lib/Api/Gateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function getSimpleCaptchaEndpoint(
6868

6969
$queryParams = [
7070
'get' => $captchaType,
71-
'c' => 'alphanumerique4to6LightCaptchaFR', // for test purpose TODO change to $type
71+
'c' => $type
7272
];
7373
if ($mode) {
7474
$queryParams['mode'] = $mode;

components/CaptchEtatBundle/src/lib/Challenge/ChallengeGenerator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@ class ChallengeGenerator
2121
protected TranslatorInterface $translator;
2222
protected CaptchEtatLogger $logger;
2323
protected Gateway $gateway;
24+
protected string $captchetatType;
2425

2526
public function __construct(
2627
LocaleConverterInterface $localeConverter,
2728
ConfigResolverInterface $configResolver,
2829
Gateway $gateway,
2930
TranslatorInterface $translator,
30-
CaptchEtatLogger $logger
31+
CaptchEtatLogger $logger,
32+
string $captchetatType
3133
) {
3234
$this->gateway = $gateway;
3335
$this->logger = $logger;
3436
$this->translator = $translator;
3537
$this->localeConverter = $localeConverter;
3638
$this->configResolver = $configResolver;
39+
$this->captchetatType = $captchetatType;
3740
}
3841

3942
public function __invoke()
@@ -113,6 +116,8 @@ public function getType(string $lang): string
113116
$type = 'numerique6_7CaptchaEN';
114117
}
115118

119+
$type = empty($this->captchetatType) ? $type : $this->captchetatType;
120+
116121
return $type;
117122
}
118123
}

0 commit comments

Comments
 (0)