Add flow registration validation support
This commit is contained in:
parent
2f96c759ab
commit
633e30ae47
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -94,12 +103,13 @@ class CaptchaValidator
|
|||
}
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the expected CAPTCHA code.
|
||||
|
|
Loading…
Reference in New Issue