38 Commits

Author SHA1 Message Date
d6c6de0f83 Merge branch 'master' of github.com:Gregwar/CaptchaBundle
Conflicts:
	composer.json
2015-01-27 17:12:52 +01:00
ac95e1d4b1 v1.0.12 2015-01-27 17:11:57 +01:00
c844d0a440 Merge pull request #113 from waldermort/patch-1
Fix: Bypass code incorrectly compared
2015-01-13 14:43:37 +01:00
f20fc3c3b7 Merge pull request #114 from waldermort/patch-2
Fix: Numeric bypass code defaults to integer type
2015-01-13 14:42:45 +01:00
0cb34f33b0 Fix: Numeric bypass code defaults to integer type
When adding a numeric only bypass code into config.yml, it is treated as an integer which causes validation to fail. A workaround is to surround the parameter with double quotes but many users may not be aware of this. This fix will explicitly convert it to a string.
2015-01-13 20:16:15 +08:00
843f367540 Fix: Bypass code incorrectly compared
When the bypass code is given the value of '0', PHP equates it to boolean false causing the validation to fail.
2015-01-13 20:10:53 +08:00
94c5f0a03b Merge pull request #107 from Hast/translation/ukrainian
Added ukrainian translation
2014-09-26 21:07:06 +02:00
6a522b7043 Added ukrainian translation 2014-09-26 22:03:38 +03:00
62e44cd388 Merge pull request #103 from kuborgh/cache
HTTP 1.1 equivalent to Pragma: no-cache
2014-08-27 16:12:32 +02:00
459901319c HTTP 1.1 equivalent to Pragma: no-cache
See http://stackoverflow.com/questions/10314174/difference-between-pragma-and-cache-control-headers for detailed explanation
2014-08-27 14:34:57 +02:00
1c542e1164 Merge pull request #102 from kuborgh/cache
Added no-cache header
2014-08-27 13:06:49 +02:00
dc3e0c6495 Added no-cache header
This prevents Varnish from caching the captcha image
2014-08-27 12:29:12 +02:00
bd208c45a8 Merge pull request #94 from piotrantosik/psr
update docblock, fix typos, improve composer.json
2014-08-19 12:28:19 +02:00
9614209d83 update docblock, fix typos, improve composer.json 2014-08-19 12:19:27 +02:00
90088c80fc Merge pull request #100 from stefan-bofirov-dnh/master
Added bulgarian translation
2014-08-19 10:12:21 +02:00
06c713fbb4 Added bulgarian translation 2014-08-17 16:17:41 +03:00
162a2a87cd Changing gcp to gcb 2014-07-31 16:41:27 +02:00
fe3df8a640 Merge pull request #98 from Adezandee/master
[BUG] Fix session key variable naming
2014-07-31 11:40:52 -03:00
b87b05e29d Fix session key variable naming 2014-07-29 19:03:41 +02:00
cdf64984b7 Merge pull request #95 from piotrantosik/issue
fix multiple captcha on page
2014-07-24 18:07:26 -03:00
458e7cafef fix multiple captcha on page 2014-07-21 14:46:14 +02:00
ce96122ef2 Merge pull request #93 from aitboudad/patch-1
fixed typo.
2014-07-10 11:32:26 +02:00
c4c69b0a47 fixed typo. 2014-07-10 10:30:57 +01:00
6b573121a5 Merge pull request #92 from dypa/patch-1
Update CaptchaValidator.php
2014-07-03 10:55:24 +02:00
e34e191d32 Update CaptchaValidator.php
fix typo (lol)
2014-07-03 12:50:49 +04:00
7dd05f5389 Merge pull request #88 from mseshachalam/patch-1
Patch 1
2014-05-14 11:55:23 +02:00
de0d9408d6 corrected typos 2014-05-14 10:35:18 +05:30
cb45fe2847 separated class names to parameters
Easier to override the services of this bundle without compiler pass. (http://symfony.com/doc/current/cookbook/bundles/override.html)
2014-05-14 10:32:02 +05:30
1fec709d05 Merge branch 'master' of github.com:Gregwar/CaptchaBundle 2014-05-07 17:19:30 +02:00
35cbc6226c Adding text & background color to persist options (see #18) 2014-05-07 17:18:57 +02:00
7c38520965 Merge pull request #84 from piotrantosik/master
add polish translation
2014-04-07 10:15:46 +02:00
277e3baff0 add pl translation 2014-04-07 09:41:36 +02:00
f2e07fe6f2 Merge branch 'master' of github.com:Gregwar/CaptchaBundle 2014-03-19 16:15:10 +01:00
ab786e3b0e Updating to v1.0.11 2014-03-19 16:14:56 +01:00
f206bb66cc Merge pull request #80 from gondo/master
added Czech translation
2014-03-06 17:23:06 +01:00
3340af5c43 Create validators.cs.yml 2014-03-06 16:24:41 +01:00
bc3fdda50b Rename gregwar_captcha.cz.yml to gregwar_captcha.cs.yml 2014-03-06 16:22:57 +01:00
b2340539d2 Create gregwar_captcha.cz.yml 2014-03-06 16:22:28 +01:00
17 changed files with 62 additions and 54 deletions

View File

@ -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\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');
@ -52,8 +53,9 @@ 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;
}
}

View File

@ -51,4 +51,3 @@ class Configuration implements ConfigurationInterface
return $treeBuilder;
}
}

View File

@ -160,4 +160,3 @@ class CaptchaGenerator
return $phrase;
}
}

View File

@ -103,4 +103,3 @@ class ImageFileHandler
}
}
}

View File

@ -126,7 +126,7 @@ You can define the following configuration options globally or on the CaptchaTyp
* **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 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)

View File

@ -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%

View File

@ -0,0 +1 @@
Renew: Обнови

View File

@ -0,0 +1 @@
Renew: Obnovit

View File

@ -0,0 +1 @@
Renew: Przeładuj

View File

@ -0,0 +1 @@
Renew: Оновити

View File

@ -0,0 +1 @@
Bad code value: Грешен код

View File

@ -0,0 +1 @@
Bad code value: Špatný kontrolní kód

View File

@ -0,0 +1 @@
Bad code value: Kod jest niepoprawny

View File

@ -0,0 +1 @@
Bad code value: Невірний код

View File

@ -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,33 +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(
@ -122,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)
{

View File

@ -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));
}
}

View File

@ -18,7 +18,9 @@
],
"require": {
"php": ">=5.3.0",
"gregwar/captcha": "v1.0.10"
"gregwar/captcha": "~1.0.12",
"symfony/framework-bundle": "~2.1",
"symfony/form": "~2.1"
},
"autoload": {
"psr-0": {