mise à niveau pour utilisation avec flow

This commit is contained in:
Benjamin Gaudé 2021-05-28 12:11:05 +02:00
parent 3ccfdf1c93
commit d43cc35eda
3 changed files with 20 additions and 8 deletions

View File

@ -70,7 +70,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']
);
$event = \Symfony\Component\HttpKernel\Kernel::VERSION >= 2.3 ? FormEvents::POST_SUBMIT : FormEvents::POST_BIND;
$builder->addEventListener($event, array($validator, 'validate'));
@ -129,6 +130,7 @@ class CaptchaType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$this->options['mapped'] = false;
$this->options['request'] = null;
$resolver->setDefaults($this->options);
}

View File

@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Captcha validator
@ -46,6 +47,13 @@ class CaptchaValidator
*/
private $translator;
/**
* Request
*
* @var Request
*/
private $req;
/**
* @param TranslatorInterface $translator
* @param SessionInterface $session
@ -54,7 +62,7 @@ class CaptchaValidator
* @param string $bypassCode
* @param int $humanity
*/
public function __construct(TranslatorInterface $translator, SessionInterface $session, $key, $invalidMessage, $bypassCode, $humanity)
public function __construct(TranslatorInterface $translator, SessionInterface $session, $key, $invalidMessage, $bypassCode, $humanity, Request $req = null)
{
$this->translator = $translator;
$this->session = $session;
@ -62,6 +70,7 @@ class CaptchaValidator
$this->invalidMessage = $invalidMessage;
$this->bypassCode = (string)$bypassCode;
$this->humanity = $humanity;
$this->req = $req;
}
/**
@ -90,10 +99,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": "captcha-bundle",
"description": "Captcha bundle",
"keywords": ["symfony2", "captcha", "bot", "visual", "code", "security", "spam"],
"homepage": "https://github.com/Gregwar/CaptchaBundle",
"homepage": "https://github.com/Cadoles/CaptchaBundle",
"license": "MIT",
"authors": [
{