Compare commits
72 Commits
Author | SHA1 | Date | |
---|---|---|---|
c221d9cb42 | |||
7574ad33f1 | |||
d80ff1959b | |||
694994c3c2 | |||
01429c4486 | |||
6032e5df52 | |||
d77e0b1f2a | |||
a4176fcf74 | |||
909d1a3773 | |||
d6c6de0f83 | |||
ac95e1d4b1 | |||
c844d0a440 | |||
f20fc3c3b7 | |||
0cb34f33b0 | |||
843f367540 | |||
94c5f0a03b | |||
6a522b7043 | |||
62e44cd388 | |||
459901319c | |||
1c542e1164 | |||
dc3e0c6495 | |||
bd208c45a8 | |||
9614209d83 | |||
90088c80fc | |||
06c713fbb4 | |||
162a2a87cd | |||
fe3df8a640 | |||
b87b05e29d | |||
cdf64984b7 | |||
458e7cafef | |||
ce96122ef2 | |||
c4c69b0a47 | |||
6b573121a5 | |||
e34e191d32 | |||
7dd05f5389 | |||
de0d9408d6 | |||
cb45fe2847 | |||
1fec709d05 | |||
35cbc6226c | |||
7c38520965 | |||
277e3baff0 | |||
f2e07fe6f2 | |||
ab786e3b0e | |||
f206bb66cc | |||
3340af5c43 | |||
bc3fdda50b | |||
b2340539d2 | |||
8199d20092 | |||
8770c50ff0 | |||
721a2b1f3d | |||
e2f1966bfb | |||
2f508ddd07 | |||
2e803e1471 | |||
800643d72c | |||
c09b7245b1 | |||
c3c8904862 | |||
9d4f95e39b | |||
107dbe33e4 | |||
6b4e7db721 | |||
aef6a785ca | |||
fc72ab4f6c | |||
e3727a975d | |||
9d741e0ac6 | |||
0ab26cac81 | |||
ddab3ef005 | |||
0b08b38cb0 | |||
3f64e064d3 | |||
9578caab10 | |||
7f30646c68 | |||
daec205870 | |||
1881d292b8 | |||
181b0cd0d0 |
@ -2,9 +2,9 @@
|
||||
|
||||
namespace Gregwar\CaptchaBundle\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Generates a captcha via a URL
|
||||
@ -16,12 +16,13 @@ class CaptchaController extends Controller
|
||||
/**
|
||||
* Action that is used to generate the captcha, save its code, and stream the image
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* @param string $key
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return Response
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function generateCaptchaAction(Request $request, $key)
|
||||
public function generateCaptchaAction($key)
|
||||
{
|
||||
$options = $this->container->getParameter('gregwar_captcha.config');
|
||||
$session = $this->get('session');
|
||||
@ -36,7 +37,7 @@ class CaptchaController extends Controller
|
||||
}
|
||||
|
||||
if (!$isOk) {
|
||||
throw $this->createNotFoundException('Unable to generate a captcha via an URL with this session key.');
|
||||
return $this->error($options);
|
||||
}
|
||||
|
||||
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
|
||||
@ -52,8 +53,31 @@ class CaptchaController extends Controller
|
||||
|
||||
$response = new Response($generator->generate($options));
|
||||
$response->headers->set('Content-type', 'image/jpeg');
|
||||
$response->headers->set('Pragma', 'no-cache');
|
||||
$response->headers->set('Cache-Control', 'no-cache');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty image with status code 428 Precondition Required
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
protected function error($options)
|
||||
{
|
||||
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
|
||||
$generator = $this->container->get('gregwar_captcha.generator');
|
||||
$generator->setPhrase('');
|
||||
|
||||
$response = new Response($generator->generate($options));
|
||||
$response->setStatusCode(428);
|
||||
$response->headers->set('Content-type', 'image/jpeg');
|
||||
$response->headers->set('Pragma', 'no-cache');
|
||||
$response->headers->set('Cache-Control', 'no-cache');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,11 +42,12 @@ class Configuration implements ConfigurationInterface
|
||||
->scalarNode('max_front_lines')->defaultValue(null)->end()
|
||||
->scalarNode('max_behind_lines')->defaultValue(null)->end()
|
||||
->scalarNode('interpolation')->defaultValue(true)->end()
|
||||
->arrayNode('background_color')->prototype('scalar')->end()
|
||||
->arrayNode('text_color')->prototype('scalar')->end()->end()
|
||||
->arrayNode('background_color')->prototype('scalar')->end()->end()
|
||||
->scalarNode('disabled')->defaultValue(false)->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class GregwarCaptchaExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* @param array $configs
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
@ -33,10 +33,6 @@ class GregwarCaptchaExtension extends Extension
|
||||
$container->setParameter('gregwar_captcha.config.expiration', $config['expiration']);
|
||||
$container->setParameter('gregwar_captcha.config.whitelist_key', $config['whitelist_key']);
|
||||
|
||||
if ($config['reload'] && !$config['as_url']) {
|
||||
throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information');
|
||||
}
|
||||
|
||||
$resources = $container->getParameter('twig.form.resources');
|
||||
$container->setParameter('twig.form.resources', array_merge(array('GregwarCaptchaBundle::captcha.html.twig'), $resources));
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
namespace Gregwar\CaptchaBundle\Generator;
|
||||
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Gregwar\Captcha\CaptchaBuilder;
|
||||
use Gregwar\Captcha\PhraseBuilder;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
@ -18,7 +19,7 @@ use Gregwar\Captcha\PhraseBuilderInterface;
|
||||
class CaptchaGenerator
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\Routing\RouterInterface
|
||||
* @var RouterInterface
|
||||
*/
|
||||
protected $router;
|
||||
|
||||
@ -38,12 +39,17 @@ class CaptchaGenerator
|
||||
protected $imageFileHandler;
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\Routing\RouterInterface $router
|
||||
* @param RouterInterface $router
|
||||
* @param CaptchaBuilderInterface $builder
|
||||
* @param ImageFileHandlerInterface $imageFileHandler
|
||||
* @param PhraseBuilderInterface $phraseBuilder
|
||||
* @param ImageFileHandler $imageFileHandler
|
||||
*/
|
||||
public function __construct(RouterInterface $router, CaptchaBuilderInterface $builder, PhraseBuilderInterface $phraseBuilder, ImageFileHandler $imageFileHandler)
|
||||
{
|
||||
public function __construct(
|
||||
RouterInterface $router,
|
||||
CaptchaBuilderInterface $builder,
|
||||
PhraseBuilderInterface $phraseBuilder,
|
||||
ImageFileHandler $imageFileHandler
|
||||
) {
|
||||
$this->router = $router;
|
||||
$this->builder = $builder;
|
||||
$this->phraseBuilder = $phraseBuilder;
|
||||
@ -53,7 +59,6 @@ class CaptchaGenerator
|
||||
/**
|
||||
* Get the captcha URL, stream, or filename that will go in the image's src attribute
|
||||
*
|
||||
* @param $key
|
||||
* @param array $options
|
||||
*
|
||||
* @return array
|
||||
@ -86,7 +91,6 @@ class CaptchaGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
@ -98,8 +102,17 @@ class CaptchaGenerator
|
||||
$this->builder->setMaxFrontLines($options['max_front_lines']);
|
||||
$this->builder->setMaxBehindLines($options['max_behind_lines']);
|
||||
|
||||
if ($options['background_color'] != array()) {
|
||||
if (count($options['background_color'])!=3) {
|
||||
if (isset($options['text_color']) && $options['text_color']) {
|
||||
if (count($options['text_color']) !== 3) {
|
||||
throw new \RuntimeException('text_color should be an array of r, g and b');
|
||||
}
|
||||
|
||||
$color = $options['text_color'];
|
||||
$this->builder->setTextColor($color[0], $color[1], $color[2]);
|
||||
}
|
||||
|
||||
if (isset($options['background_color']) && $options['background_color']) {
|
||||
if (count($options['background_color']) !== 3) {
|
||||
throw new \RuntimeException('background_color should be an array of r, g and b');
|
||||
}
|
||||
|
||||
@ -133,7 +146,6 @@ class CaptchaGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
@ -151,4 +163,3 @@ class CaptchaGenerator
|
||||
return $phrase;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,4 +103,3 @@ class ImageFileHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
||||
Copyright (c) <2011-2013> Grégoire Passault
|
||||
Copyright (c) <2011-2015> Grégoire Passault
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -123,10 +123,12 @@ You can define the following configuration options globally or on the CaptchaTyp
|
||||
|
||||
* **width**: the width of the captcha image (default=120)
|
||||
* **height**: the height of the captcha image (default=40)
|
||||
* **disabled**: disable globally the CAPTCHAs (can be useful in dev environment), it will
|
||||
still appear but won't be editable and won't be checked
|
||||
* **length**: the length of the captcha (number of chars, default 5)
|
||||
* **quality**: jpeg quality of captchas (default=15)
|
||||
* **quality**: jpeg quality of captchas (default=30)
|
||||
* **charset**: the charset used for code generation (default=abcdefhjkmnprstuvwxyz23456789)
|
||||
* **font**: the font to use (default=Generator/Font/captcha.ttf)
|
||||
* **font**: the font to use (default is random among some pre-provided fonts), this should be an absolute path
|
||||
* **keep_value**: the value will be the same until the form is posted, even if the page is refreshed (default=true)
|
||||
* **as_file**: if set to true an image file will be created instead of embedding to please IE6/7 (default=false)
|
||||
* **as_url**: if set to true, a URL will be used in the image tag and will handle captcha generation. This can be used in a multiple-server environment and support IE6/7 (default=false)
|
||||
|
@ -1,6 +1,13 @@
|
||||
parameters:
|
||||
gregwar_captcha.captcha_type.class: Gregwar\CaptchaBundle\Type\CaptchaType
|
||||
gregwar_captcha.captcha_generator.class: Gregwar\CaptchaBundle\Generator\CaptchaGenerator
|
||||
gregwar_captcha.image_file_handler.class: Gregwar\CaptchaBundle\Generator\ImageFileHandler
|
||||
gregwar_captcha.captcha_builder.class: Gregwar\Captcha\CaptchaBuilder
|
||||
gregwar_captcha.phrase_builder.class: Gregwar\Captcha\PhraseBuilder
|
||||
|
||||
services:
|
||||
captcha.type:
|
||||
class: Gregwar\CaptchaBundle\Type\CaptchaType
|
||||
class: %gregwar_captcha.captcha_type.class%
|
||||
arguments:
|
||||
- @session
|
||||
- @gregwar_captcha.generator
|
||||
@ -10,7 +17,7 @@ services:
|
||||
- { name: form.type, alias: captcha }
|
||||
|
||||
gregwar_captcha.generator:
|
||||
class: Gregwar\CaptchaBundle\Generator\CaptchaGenerator
|
||||
class: %gregwar_captcha.captcha_generator.class%
|
||||
arguments:
|
||||
- @router
|
||||
- @gregwar_captcha.captcha_builder
|
||||
@ -18,7 +25,7 @@ services:
|
||||
- @gregwar_captcha.image_file_handler
|
||||
|
||||
gregwar_captcha.image_file_handler:
|
||||
class: Gregwar\CaptchaBundle\Generator\ImageFileHandler
|
||||
class: %gregwar_captcha.image_file_handler.class%
|
||||
arguments:
|
||||
- %gregwar_captcha.config.image_folder%
|
||||
- %gregwar_captcha.config.web_path%
|
||||
@ -26,7 +33,7 @@ services:
|
||||
- %gregwar_captcha.config.expiration%
|
||||
|
||||
gregwar_captcha.captcha_builder:
|
||||
class: Gregwar\Captcha\CaptchaBuilder
|
||||
class: %gregwar_captcha.captcha_builder.class%
|
||||
|
||||
gregwar_captcha.phrase_builder:
|
||||
class: Gregwar\Captcha\PhraseBuilder
|
||||
class: %gregwar_captcha.phrase_builder.class%
|
||||
|
1
Resources/translations/gregwar_captcha.bg.yml
Normal file
1
Resources/translations/gregwar_captcha.bg.yml
Normal file
@ -0,0 +1 @@
|
||||
Renew: Обнови
|
1
Resources/translations/gregwar_captcha.cs.yml
Normal file
1
Resources/translations/gregwar_captcha.cs.yml
Normal file
@ -0,0 +1 @@
|
||||
Renew: Obnovit
|
1
Resources/translations/gregwar_captcha.de.yml
Normal file
1
Resources/translations/gregwar_captcha.de.yml
Normal file
@ -0,0 +1 @@
|
||||
Renew: Erneuern
|
1
Resources/translations/gregwar_captcha.en.yml
Normal file
1
Resources/translations/gregwar_captcha.en.yml
Normal file
@ -0,0 +1 @@
|
||||
Renew: Renew
|
1
Resources/translations/gregwar_captcha.nl.yml
Normal file
1
Resources/translations/gregwar_captcha.nl.yml
Normal file
@ -0,0 +1 @@
|
||||
Renew: Vernieuwen
|
1
Resources/translations/gregwar_captcha.pl.yml
Normal file
1
Resources/translations/gregwar_captcha.pl.yml
Normal file
@ -0,0 +1 @@
|
||||
Renew: Przeładuj
|
1
Resources/translations/gregwar_captcha.pt_BR.yml
Normal file
1
Resources/translations/gregwar_captcha.pt_BR.yml
Normal file
@ -0,0 +1 @@
|
||||
Renew: Regerar
|
1
Resources/translations/gregwar_captcha.ru.yml
Normal file
1
Resources/translations/gregwar_captcha.ru.yml
Normal file
@ -0,0 +1 @@
|
||||
Renew: Обновить
|
1
Resources/translations/gregwar_captcha.uk.yml
Normal file
1
Resources/translations/gregwar_captcha.uk.yml
Normal file
@ -0,0 +1 @@
|
||||
Renew: Оновити
|
1
Resources/translations/validators.bg.yml
Normal file
1
Resources/translations/validators.bg.yml
Normal file
@ -0,0 +1 @@
|
||||
Bad code value: Грешен код
|
1
Resources/translations/validators.cs.yml
Normal file
1
Resources/translations/validators.cs.yml
Normal file
@ -0,0 +1 @@
|
||||
Bad code value: Špatný kontrolní kód
|
1
Resources/translations/validators.de.yml
Normal file
1
Resources/translations/validators.de.yml
Normal file
@ -0,0 +1 @@
|
||||
Bad code value: Code stimmt nicht überein
|
1
Resources/translations/validators.en.yml
Normal file
1
Resources/translations/validators.en.yml
Normal file
@ -0,0 +1 @@
|
||||
Bad code value: Code does not match
|
1
Resources/translations/validators.nl.yml
Normal file
1
Resources/translations/validators.nl.yml
Normal file
@ -0,0 +1 @@
|
||||
Bad code value: Code komt niet overeen
|
1
Resources/translations/validators.pl.yml
Normal file
1
Resources/translations/validators.pl.yml
Normal file
@ -0,0 +1 @@
|
||||
Bad code value: Kod jest niepoprawny
|
1
Resources/translations/validators.pt_BR.yml
Normal file
1
Resources/translations/validators.pt_BR.yml
Normal file
@ -0,0 +1 @@
|
||||
Bad code value: Código de verificação inválido
|
1
Resources/translations/validators.ru.yml
Normal file
1
Resources/translations/validators.ru.yml
Normal file
@ -0,0 +1 @@
|
||||
Bad code value: Неправильный код
|
1
Resources/translations/validators.uk.yml
Normal file
1
Resources/translations/validators.uk.yml
Normal file
@ -0,0 +1 @@
|
||||
Bad code value: Невірний код
|
@ -22,18 +22,12 @@ use Gregwar\CaptchaBundle\Generator\CaptchaGenerator;
|
||||
class CaptchaType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface
|
||||
* @var SessionInterface
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* The session key
|
||||
* @var string
|
||||
*/
|
||||
protected $key = null;
|
||||
|
||||
/**
|
||||
* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator
|
||||
* @var CaptchaGenerator
|
||||
*/
|
||||
protected $generator;
|
||||
|
||||
@ -49,9 +43,10 @@ class CaptchaType extends AbstractType
|
||||
private $options = array();
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
|
||||
* @param \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator
|
||||
* @param array $options
|
||||
* @param SessionInterface $session
|
||||
* @param CaptchaGenerator $generator
|
||||
* @param TranslatorInterface $translator
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(SessionInterface $session, CaptchaGenerator $generator, TranslatorInterface $translator, $options)
|
||||
{
|
||||
@ -62,17 +57,14 @@ class CaptchaType extends AbstractType
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\Form\FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$this->key = 'gcb_'.$builder->getForm()->getName();
|
||||
|
||||
$validator = new CaptchaValidator(
|
||||
$this->translator,
|
||||
$this->session,
|
||||
$this->key,
|
||||
sprintf('gcb_%s', $builder->getForm()->getName()),
|
||||
$options['invalid_message'],
|
||||
$options['bypass_code'],
|
||||
$options['humanity']
|
||||
@ -82,29 +74,31 @@ class CaptchaType extends AbstractType
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\Form\FormView $view
|
||||
* @param \Symfony\Component\Form\FormInterface $form
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$isHuman = false;
|
||||
if ($options['reload'] && !$options['as_url']) {
|
||||
throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information');
|
||||
}
|
||||
|
||||
$sessionKey = sprintf('gcb_%s', $form->getName());
|
||||
$isHuman = false;
|
||||
|
||||
if ($options['humanity'] > 0) {
|
||||
$humanityKey = $this->key.'_humanity';
|
||||
$humanityKey = sprintf('%s_humanity', $sessionKey);
|
||||
if ($this->session->get($humanityKey, 0) > 0) {
|
||||
$isHuman = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($options['as_url']) {
|
||||
$key = $this->key;
|
||||
$keys = $this->session->get($options['whitelist_key'], array());
|
||||
if (!in_array($key, $keys)) {
|
||||
$keys[] = $key;
|
||||
if (!in_array($sessionKey, $keys)) {
|
||||
$keys[] = $sessionKey;
|
||||
}
|
||||
$this->session->set($options['whitelist_key'], $keys);
|
||||
$options['session_key'] = $this->key;
|
||||
$options['session_key'] = $sessionKey;
|
||||
}
|
||||
|
||||
$view->vars = array_merge($view->vars, array(
|
||||
@ -118,15 +112,15 @@ class CaptchaType extends AbstractType
|
||||
));
|
||||
|
||||
$persistOptions = array();
|
||||
foreach (array('phrase', 'width', 'height', 'distortion', 'length', 'quality') as $key) {
|
||||
foreach (array('phrase', 'width', 'height', 'distortion', 'length', 'quality', 'background_color', 'text_color') as $key) {
|
||||
$persistOptions[$key] = $options[$key];
|
||||
}
|
||||
|
||||
$this->session->set($this->key, $persistOptions);
|
||||
$this->session->set($sessionKey, $persistOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ use Symfony\Component\Translation\TranslatorInterface;
|
||||
class CaptchaValidator
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface
|
||||
* @var SessionInterface
|
||||
*/
|
||||
private $session;
|
||||
|
||||
@ -47,10 +47,12 @@ class CaptchaValidator
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
|
||||
* @param string $key
|
||||
* @param string $invalidMessage
|
||||
* @param string|null $bypassCode
|
||||
* @param TranslatorInterface $translator
|
||||
* @param SessionInterface $session
|
||||
* @param string $key
|
||||
* @param string $invalidMessage
|
||||
* @param string $bypassCode
|
||||
* @param int $humanity
|
||||
*/
|
||||
public function __construct(TranslatorInterface $translator, SessionInterface $session, $key, $invalidMessage, $bypassCode, $humanity)
|
||||
{
|
||||
@ -58,7 +60,7 @@ class CaptchaValidator
|
||||
$this->session = $session;
|
||||
$this->key = $key;
|
||||
$this->invalidMessage = $invalidMessage;
|
||||
$this->bypassCode = $bypassCode;
|
||||
$this->bypassCode = (string)$bypassCode;
|
||||
$this->humanity = $humanity;
|
||||
}
|
||||
|
||||
@ -67,7 +69,7 @@ class CaptchaValidator
|
||||
*/
|
||||
public function validate(FormEvent $event)
|
||||
{
|
||||
$form = $form = $event->getForm();
|
||||
$form = $event->getForm();
|
||||
|
||||
$code = $form->getData();
|
||||
$expectedCode = $this->getExpectedCode();
|
||||
@ -80,7 +82,7 @@ class CaptchaValidator
|
||||
}
|
||||
}
|
||||
|
||||
if (!($code && is_string($code) && ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) {
|
||||
if (!($code !== null && is_string($code) && ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) {
|
||||
$form->addError(new FormError($this->translator->trans($this->invalidMessage, array(), 'validators')));
|
||||
} else {
|
||||
if ($this->humanity > 0) {
|
||||
@ -112,7 +114,7 @@ class CaptchaValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreive the humanity
|
||||
* Retrieve the humanity
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
@ -157,6 +159,6 @@ class CaptchaValidator
|
||||
*/
|
||||
protected function compare($code, $expectedCode)
|
||||
{
|
||||
return ($expectedCode && is_string($expectedCode) && $this->niceize($code) == $this->niceize($expectedCode));
|
||||
return ($expectedCode !== null && is_string($expectedCode) && $this->niceize($code) == $this->niceize($expectedCode));
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,13 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"gregwar/captcha": "v1.0.7"
|
||||
"gregwar/captcha": "~1.1",
|
||||
"symfony/framework-bundle": "~2.1",
|
||||
"symfony/form": "~2.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Gregwar\\CaptchaBundle": ""
|
||||
"psr-4": {
|
||||
"Gregwar\\CaptchaBundle\\": "/"
|
||||
}
|
||||
},
|
||||
"target-dir": "Gregwar/CaptchaBundle"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user