Compare commits

...

3 Commits

Author SHA1 Message Date
wpetit 5778c54ae0 Add missing initialization 2022-02-09 10:19:13 +01:00
Benjamin Gaudé 9b65966d27 update composer.json 2021-05-28 11:53:54 +02:00
Benjamin Gaudé 633e30ae47 Add flow registration validation support 2021-05-28 08:08:42 +02:00
3 changed files with 21 additions and 8 deletions

View File

@ -62,7 +62,8 @@ class CaptchaType extends AbstractType
sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']),
$options['invalid_message'],
$options['bypass_code'],
$options['humanity']
$options['humanity'],
$options['request']
);
$builder->addEventListener(FormEvents::POST_SUBMIT, array($validator, 'validate'));
@ -121,6 +122,7 @@ class CaptchaType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$this->options['mapped'] = false;
$this->options['request'] = null;
$resolver->setDefaults($this->options);
}

View File

@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Captcha validator.
@ -54,13 +55,21 @@ class CaptchaValidator
*/
private $translator;
/**
* Request
*
* @var Request
*/
private $req;
public function __construct(
TranslatorInterface $translator,
SessionInterface $session,
string $key,
string $invalidMessage,
?string $bypassCode,
int $humanity
int $humanity,
?Request $req
) {
$this->translator = $translator;
$this->session = $session;
@ -68,6 +77,7 @@ class CaptchaValidator
$this->invalidMessage = $invalidMessage;
$this->bypassCode = $bypassCode;
$this->humanity = $humanity;
$this->req = $req;
}
public function validate(FormEvent $event): void
@ -94,10 +104,11 @@ class CaptchaValidator
}
}
$this->session->remove($this->key);
if ($this->session->has($this->key.'_fingerprint')) {
$this->session->remove($this->key.'_fingerprint');
if (null == $this->req || 1 < $this->req->get('flow_registration_step')) {
$this->session->remove($this->key);
if ($this->session->has($this->key.'_fingerprint')) {
$this->session->remove($this->key.'_fingerprint');
}
}
}

View File

@ -1,9 +1,9 @@
{
"name": "gregwar/captcha-bundle",
"name": "cadoles/captcha",
"type": "symfony-bundle",
"description": "Captcha bundle",
"keywords": ["symfony2", "symfony", "captcha", "bot", "visual", "code", "security", "spam"],
"homepage": "https://github.com/Gregwar/CaptchaBundle",
"homepage": "https://github.com/Cadoles/CaptchaBundle",
"license": "MIT",
"authors": [
{