From c87a2b1d56bd252591ba609de6dc632bfd1e7d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20CROMBEZ?= Date: Fri, 8 Jun 2012 03:23:41 +0300 Subject: [PATCH 1/8] Update 2.0 --- Validator/CaptchaValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Validator/CaptchaValidator.php b/Validator/CaptchaValidator.php index f815c90..9ec42ea 100644 --- a/Validator/CaptchaValidator.php +++ b/Validator/CaptchaValidator.php @@ -3,7 +3,7 @@ namespace Gregwar\CaptchaBundle\Validator; use Symfony\Component\Form\FormValidatorInterface; -use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormError; From 649853839792e4460b75b65445a2cbce06eaf9ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20CROMBEZ?= Date: Fri, 8 Jun 2012 03:23:59 +0300 Subject: [PATCH 2/8] Update 2.0 --- Type/CaptchaType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index e4f0e69..e6309fe 100755 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -2,7 +2,7 @@ namespace Gregwar\CaptchaBundle\Type; -use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Form\FormView; From bbe3a8340adea9f93f3103216a3acd2fe94e8ddb Mon Sep 17 00:00:00 2001 From: Gregwar Date: Fri, 8 Jun 2012 17:48:43 +0200 Subject: [PATCH 3/8] Changing back the Session namespace for 2.0 --- Validator/CaptchaValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Validator/CaptchaValidator.php b/Validator/CaptchaValidator.php index f815c90..9ec42ea 100644 --- a/Validator/CaptchaValidator.php +++ b/Validator/CaptchaValidator.php @@ -3,7 +3,7 @@ namespace Gregwar\CaptchaBundle\Validator; use Symfony\Component\Form\FormValidatorInterface; -use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormError; From bb30859e0576f53f46f85aff3d0f3fcaaabcfb51 Mon Sep 17 00:00:00 2001 From: Gregwar Date: Thu, 14 Jun 2012 21:01:31 +0200 Subject: [PATCH 4/8] Clarifying deps for 2.0 (should fix #22) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4f4965a..1a83d70 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Add the following lines to your `deps` file: [GregwarCaptchaBundle] git=git://github.com/Gregwar/CaptchaBundle.git target=/bundles/Gregwar/CaptchaBundle + version=origin/2.0 <- add this if you are using Symfony 2.0 ``` Now, run the vendors script to download the bundle: From 2872d35dd94dc257ef99a499e98348546e990151 Mon Sep 17 00:00:00 2001 From: Gregwar Date: Fri, 15 Jun 2012 13:55:05 +0200 Subject: [PATCH 5/8] Updating LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index ae9440b..bcf9213 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) <2011> Grégoire Passault +Copyright (c) <2012> 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 From 620b3c0fbac9d884d622a12ddd2ee8e948b65d84 Mon Sep 17 00:00:00 2001 From: Gregwar Date: Fri, 22 Jun 2012 19:04:05 +0200 Subject: [PATCH 6/8] Adding composer support --- README.md | 12 ++++++++++++ composer.json | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 composer.json diff --git a/README.md b/README.md index 1a83d70..5957265 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,20 @@ $ git submodule add git://github.com/Gregwar/CaptchaBundle.git vendor/bundles/Gr $ git submodule update --init ``` +***Using Composer*** + +Add the following to the "require" section of your `composer.json` file: + +``` + "gregwar/captcha-bundle": "1.0.0" +``` + +And update your dependencies + ### Step 2: Configure the Autoloader +If you use composer, you can skip this step. + Now you will need to add the `Gregwar` namespace to your autoloader: ``` php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..1b4df7e --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "gregwar/captcha-bundle", + "type": "captcha-bundle", + "description": "Captcha bundle", + "keywords": ["symfony2", "captcha", "bot", "visual", "code", "security", "spam"], + "homepage": "https://github.com/Gregwar/ImageBundle", + "license": "MIT", + "authors": [ + { + "name": "Grégoire Passault", + "email": "g.passault@gmail.com", + "homepage": "http://www.gregwar.com/" + } + ], + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-0": { + "Gregwar\\CaptchaBundle": "" + } + }, + "target-dir": "Gregwar/CaptchaBundle" +} From 7368fded229ad4342d8e5a2736714c84990be0cc Mon Sep 17 00:00:00 2001 From: Jeremy Livingston Date: Fri, 29 Jun 2012 10:23:05 -0400 Subject: [PATCH 7/8] Add invalid_message configuration option Conflicts: Type/CaptchaType.php --- DependencyInjection/Configuration.php | 1 + README.md | 1 + Type/CaptchaType.php | 17 ++++++++++++++++- Validator/CaptchaValidator.php | 12 +++++++++--- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 002a71e..1878e26 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -31,6 +31,7 @@ public function getConfigTreeBuilder() ->scalarNode('gc_freq')->defaultValue(100)->end() ->scalarNode('expiration')->defaultValue(60)->end() ->scalarNode('quality')->defaultValue(15)->end() + ->scalarNode('invalid_message')->defaultValue('Bad code value')->end() ->end() ; return $treeBuilder; diff --git a/README.md b/README.md index 5957265..f0fd05e 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ You can define the following type option : * **web_path**: absolute path to public web folder (default="%kernel.root_dir%/../web") * **gc_freq**: frequency of garbage collection in fractions of 1 (default=100) * **expiration**: maximum lifetime of captcha image files in minutes (default=60) +* **invalid_message**: error message displayed when an non-matching code is submitted (default="Bad code value") Example : diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index e6309fe..22e7092 100755 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -45,7 +45,7 @@ public function buildForm(FormBuilder $builder, array $options) $this->key = $builder->getForm()->getName(); $builder->addValidator( - new CaptchaValidator($this->session, $this->key) + new CaptchaValidator($this->session, $this->key, $options['invalid_message']) ); } @@ -77,16 +77,31 @@ public function buildView(FormView $view, FormInterface $form) if ($this->options['keep_value']) { $this->session->set($this->key.'_fingerprint', $generator->getFingerprint()); } +<<<<<<< HEAD $view->set('value', ''); +======= + + $view->addVars(array( + 'captcha_width' => $options['width'], + 'captcha_height' => $options['height'], + 'captcha_code' => $captchaCode, + 'value' => '', + )); +>>>>>>> 8d54bfd... Add invalid_message configuration option } public function getDefaultOptions(array $options = array()) { +<<<<<<< HEAD $this->options = array_replace($this->options, $options); $this->options['property_path'] = false; return $this->options; +======= + $this->options['property_path'] = false; + $resolver->setDefaults($this->options); +>>>>>>> 8d54bfd... Add invalid_message configuration option } public function getParent(array $options) diff --git a/Validator/CaptchaValidator.php b/Validator/CaptchaValidator.php index 9ec42ea..abd52f6 100644 --- a/Validator/CaptchaValidator.php +++ b/Validator/CaptchaValidator.php @@ -24,10 +24,16 @@ class CaptchaValidator implements FormValidatorInterface */ private $key; - public function __construct(Session $session, $key) + /** + * Error message text for non-matching submissions + */ + private $invalidMessage; + + public function __construct(Session $session, $key, $invalidMessage) { $this->session = $session; $this->key = $key; + $this->invalidMessage = $invalidMessage; } public function validate(FormInterface $form) @@ -37,7 +43,7 @@ public function validate(FormInterface $form) if (!($code && $excepted_code && is_string($code) && is_string($excepted_code) && $this->niceize($code) == $this->niceize($excepted_code))) { - $form->addError(new FormError('Bad code value')); + $form->addError(new FormError($this->invalidMessage)); } $this->session->remove($this->key); @@ -61,7 +67,7 @@ private function getExceptedCode() /** * Process the codes */ - private function niceize($code) + private function niceize($code) { return strtr(strtolower($code), 'oil', '01l'); } From 59f4d239288764bada509205ec2c97d32f8fea78 Mon Sep 17 00:00:00 2001 From: Gregwar Date: Fri, 29 Jun 2012 17:00:56 +0200 Subject: [PATCH 8/8] Fixing conflicts errors --- Type/CaptchaType.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index 22e7092..9ce243e 100755 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -77,31 +77,16 @@ public function buildView(FormView $view, FormInterface $form) if ($this->options['keep_value']) { $this->session->set($this->key.'_fingerprint', $generator->getFingerprint()); } -<<<<<<< HEAD $view->set('value', ''); -======= - - $view->addVars(array( - 'captcha_width' => $options['width'], - 'captcha_height' => $options['height'], - 'captcha_code' => $captchaCode, - 'value' => '', - )); ->>>>>>> 8d54bfd... Add invalid_message configuration option } public function getDefaultOptions(array $options = array()) { -<<<<<<< HEAD $this->options = array_replace($this->options, $options); $this->options['property_path'] = false; return $this->options; -======= - $this->options['property_path'] = false; - $resolver->setDefaults($this->options); ->>>>>>> 8d54bfd... Add invalid_message configuration option } public function getParent(array $options)