diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index ac9d00a..c943433 100644 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -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); } diff --git a/Validator/CaptchaValidator.php b/Validator/CaptchaValidator.php index 7ee2a51..b5e4880 100644 --- a/Validator/CaptchaValidator.php +++ b/Validator/CaptchaValidator.php @@ -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'); + } } } diff --git a/composer.json b/composer.json index e249af7..8174fdb 100644 --- a/composer.json +++ b/composer.json @@ -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": [ {