106 Commits

Author SHA1 Message Date
53c25b2e9a Merge pull request #163 from hackzilla/master
Update CaptchaType.php
2016-02-02 23:40:33 +01:00
fcf8c4fd01 Update CaptchaType.php
add getBlockPrefix for Symfony3 compatibility.
2016-02-02 22:15:18 +00:00
e91cb1a3b7 Merge pull request #139 from RicoVZ/patch-1
Replaced usage of "pattern" with "path"
2015-12-30 19:19:50 +01:00
f06ff4d2c2 Clarification 2015-12-13 12:12:45 +01:00
42cb26794d Getting compatible with php>=5.3.9 2015-12-13 12:10:14 +01:00
e10494a767 Using | instead of || 2015-12-13 12:03:17 +01:00
8682eee873 README 2015-12-11 10:02:21 +01:00
c508d510ff README (see #148) 2015-12-11 10:01:40 +01:00
d328f215b2 Merge branch 'master' of github.com:Gregwar/CaptchaBundle 2015-12-07 14:25:30 +01:00
a26f03cc93 Using php 5.5 as a dependency because of ::class (see #148) 2015-12-07 14:25:06 +01:00
1862776c9a Supporting v3 2015-12-06 23:20:09 +01:00
c989422a82 Clarifying readme 2015-12-06 23:10:05 +01:00
52107b0c32 Using ::class instead of type alias (working w/ sf3, see #148) 2015-12-06 23:07:05 +01:00
e335e2a924 Merge pull request #149 from Restless-ET/patch-1
Fix YAML syntax in services.yml file
2015-12-05 14:22:11 +01:00
0971f224f4 Fix YAML syntax in services.yml file
The '@' character is supposed to be a reserved indicator for YAML. Therefore when using it at the beginning of a string (as in this case) we should enclose it in quotes.
http://yaml.org/spec/1.2/spec.html#id2774228

Also, since Symfony 2.8 this kind of usage is already marked as deprecated: https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md#yaml
2015-12-05 00:52:50 +00:00
29610bb574 Merge pull request #145 from verschoof/patch-1
Update README.md
2015-10-29 11:14:06 +01:00
018fdd3f35 Update README.md
Added composer require instead of the manual way.
Composer require will search the latest version and install it for you.
2015-10-29 10:15:34 +01:00
476530a212 Merge pull request #141 from max-kovpak/patch-2
POST_BIND deprecated
2015-09-25 09:21:54 +02:00
87d38d98a4 Update CaptchaType.php
Checkout version
2015-08-26 11:26:01 +03:00
3cc4b072c3 POST_BIND deprecated
POST_BIND deprecated since version 2.3, to be removed in 3.0. Use POST_SUBMIT instead.
2015-08-25 17:15:15 +03:00
0f5e9870f1 Merge pull request #140 from max-kovpak/patch-1
Make it more unique
2015-08-25 16:06:15 +02:00
c844cbcdbc Update CaptchaGenerator.php 2015-08-25 17:05:28 +03:00
50405a74a1 Make it more unique
If you have 2 forms on one page time will be not unique
2015-08-25 16:57:49 +03:00
84760b0a9f Merge pull request #136 from StudioMaX/patch-1
Add configureOptions method to form types for SF 2.7
2015-08-18 20:19:33 +02:00
ef281889ab Replaced usage of "pattern" with "path"
As described in issue #135
2015-08-18 09:48:41 +02:00
8468f93194 Merge pull request #81 from ChessCom/master
Add the option of custom background images for the captcha
2015-08-13 12:30:47 +02:00
fe1102f5c6 Merge pull request #138 from Burakhan/master
Adding Turkish language translate
2015-08-10 12:05:33 +02:00
f1fdfc142f Adding Turkish language translate 2015-08-10 11:15:05 +03:00
2e49f50c1a Add configureOptions method to form types for SF 2.7 2015-07-09 22:19:21 +06:00
8d3ee7334f Merge pull request #130 from amouhzi/patch-1
Arabic translations: gregwar_captcha.ar.yml
2015-05-28 00:16:52 +02:00
805e77f24a Merge pull request #131 from amouhzi/patch-2
Arabic translations: validators.ar.yml
2015-05-28 00:15:59 +02:00
adab98ad84 Arabic translations: validators.ar.yml 2015-05-27 22:49:51 +02:00
4040d06508 Arabic translations: gregwar_captcha.ar.yml 2015-05-27 22:45:26 +02:00
448b812f65 Fixing captcha url (broken in #128, see also #129) 2015-05-25 11:41:13 +02:00
4aba359e71 Merge pull request #128 from piotrantosik/master
Don't cache captcha image
2015-05-22 18:00:07 +02:00
8c39274fa4 don't cache captcha image 2015-05-22 15:01:00 +02:00
232168d408 remove comments 2015-05-19 20:20:14 +02:00
6a147a2ea3 Merge remote-tracking branch 'upstream/master' 2015-05-13 16:24:05 +02:00
c221d9cb42 Merge branch 'master' of github.com:Gregwar/CaptchaBundle 2015-05-13 08:42:05 +02:00
7574ad33f1 Updating to 1.1 2015-05-13 08:41:47 +02:00
d80ff1959b Merge pull request #125 from cordoval/minor-improvement
minor updates
2015-05-13 08:40:54 +02:00
694994c3c2 Fixing composer.json (broken in #126) 2015-05-13 08:39:21 +02:00
01429c4486 Merge pull request #126 from cordoval/move-to-psr4
move to psr4
2015-05-13 08:34:02 +02:00
6032e5df52 move to psr4 2015-05-12 20:16:59 -05:00
d77e0b1f2a minor updates 2015-05-12 20:12:49 -05:00
a4176fcf74 Merge pull request #116 from kuborgh/patch-404
fixed uncached 404
2015-02-04 16:57:21 +01:00
909d1a3773 fixed uncached 404 2015-02-04 09:29:14 +01:00
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
3d1383e8ae Merge remote-tracking branch 'upstream/master' 2014-09-04 14:04:51 +02: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
798f29e635 Merge remote-tracking branch 'upstream/master'
Conflicts:
	DependencyInjection/Configuration.php
2014-03-19 16:27:04 +01: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
8199d20092 Merge branch 'master' of github.com:Gregwar/CaptchaBundle 2014-02-14 11:29:31 +01:00
8770c50ff0 Updating gregwar/captcha to v1.0.10 2014-02-14 11:29:03 +01:00
721a2b1f3d Merge pull request #78 from verschoof/translation/english
Added English translation
2014-02-14 10:36:48 +01:00
e2f1966bfb Merge pull request #77 from verschoof/translation/dutch
Added Dutch translation
2014-02-14 10:35:57 +01:00
2f508ddd07 Added English translation 2014-02-14 10:26:58 +01:00
2e803e1471 Added Dutch translation 2014-02-14 10:24:32 +01:00
800643d72c Merge pull request #74 from regisnew/master
[ADD]
2013-11-25 02:48:00 -08:00
c09b7245b1 [ADD]
- translate validators to Brazilian portuguese.
2013-11-25 08:44:26 -02:00
c3c8904862 Merge pull request #73 from regisnew/master
[ADD]
2013-11-23 02:20:39 -08:00
9d4f95e39b [ADD]
- Brazilian Portuguese translate
2013-11-22 19:52:20 -02:00
107dbe33e4 Adding disabled global option (fixes #72) 2013-11-19 10:51:58 +01:00
34a84af209 README.md - updated docs, added background images and ignore all effects descriptions 2013-09-26 21:22:02 +02:00
3ad62e4d0d added ignore_all_effects to configuration 2013-09-26 21:10:02 +02:00
a16743a230 added background_images to configuration 2013-09-26 20:38:39 +02:00
4f46a609ba Revert "composer.json - updated to use a gregwar/captcha fork (chesscom)"
This reverts commit b085af6e00.
2013-09-26 17:28:48 +02:00
b085af6e00 composer.json - updated to use a gregwar/captcha fork (chesscom) 2013-09-25 20:53:52 +02:00
6b4e7db721 Merge branch 'master' of github.com:Gregwar/CaptchaBundle 2013-09-21 13:45:18 +02:00
aef6a785ca Merge pull request #69 from oktron/master
Add german translation
2013-09-06 08:01:56 -07:00
fc72ab4f6c Add german translation 2013-09-06 16:59:19 +02:00
33 changed files with 183 additions and 105 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\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;
}
}

View File

@ -44,10 +44,12 @@ class Configuration implements ConfigurationInterface
->scalarNode('interpolation')->defaultValue(true)->end()
->arrayNode('text_color')->prototype('scalar')->end()->end()
->arrayNode('background_color')->prototype('scalar')->end()->end()
->arrayNode('background_images')->prototype('scalar')->end()->end()
->scalarNode('disabled')->defaultValue(false)->end()
->scalarNode('ignore_all_effects')->defaultValue(false)->end()
->end()
;
return $treeBuilder;
}
}

View File

@ -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)
{

View File

@ -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
@ -71,7 +76,8 @@ class CaptchaGenerator
// Returns the image generation URL
if ($options['as_url']) {
return $this->router->generate('gregwar_captcha.generate_captcha', array('key' => $options['session_key']));
return $this->router->generate('gregwar_captcha.generate_captcha',
array('key' => $options['session_key'], 'n' => md5(microtime(true).mt_rand())));
}
return 'data:image/jpeg;base64,' . base64_encode($this->generate($options));
@ -86,7 +92,6 @@ class CaptchaGenerator
}
/**
* @param string $key
* @param array $options
*
* @return string
@ -120,6 +125,9 @@ class CaptchaGenerator
$fingerprint = isset($options['fingerprint']) ? $options['fingerprint'] : null;
$this->builder->setBackgroundImages($options['background_images']);
$this->builder->setIgnoreAllEffects($options['ignore_all_effects']);
$content = $this->builder->build(
$options['width'],
$options['height'],
@ -142,7 +150,6 @@ class CaptchaGenerator
}
/**
* @param string $key
* @param array $options
*
* @return string
@ -160,4 +167,3 @@ class CaptchaGenerator
return $phrase;
}
}

View File

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

View File

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

View File

@ -1,12 +1,15 @@
Gregwar's CaptchaBundle
=====================
The `GregwarCaptchaBundle` adds support for a "captcha" form type for the
Symfony2 form component.
The `GregwarCaptchaBundle` adds support for a captcha form type for the
Symfony form component.
Important note: the master of this repository is containing current development
in order to work with Symfony 2.1. If you are using Symfony 2.0 please checkout
the 2.0 branch.
Compatibility with Symfony
==========================
If you are using Symfony `< 2.8`, you should use version `1.*`
If you are using SYmfony `>= 2.8`, you should use version `2.*`
Installation
============
@ -17,7 +20,15 @@ Ultimately, the GregwarCaptchaBundle files should be downloaded to the
'vendor/bundles/Gregwar/CaptchaBundle' directory.
You can accomplish this several ways, depending on your personal preference.
The first method is the standard Symfony2 method.
The first method is the standard Symfony method.
***Using Composer***
Use composer require to download and install the package.
``` bash
composer require gregwar/captcha-bundle
```
***Using the vendors script***
@ -45,16 +56,6 @@ $ 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": "dev-master"
```
And update your dependencies
### Step 2: Configure the Autoloader
If you use composer, you can skip this step.
@ -101,8 +102,11 @@ You can use the "captcha" type in your forms this way:
```php
<?php
use Gregwar\CaptchaBundle\Type\CaptchaType;
// ...
$builder->add('captcha', 'captcha'); // That's all !
$builder->add('captcha', CaptchaType::class); // That's all !
// If you're using php<5.5, you can use instead:
$builder->add('captcha', 'Gregwar\CaptchaBundle\Type\CaptchaType');
// ...
```
@ -123,8 +127,10 @@ 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 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)
@ -139,14 +145,17 @@ You can define the following configuration options globally or on the CaptchaTyp
* **max_front_lines**, **max_behind_lines**: the maximum number of lines to draw on top/behind the image. `0` will draw no lines; `null` will use the default algorithm (the
number of lines depends on the size of the image). (default=null)
* **background_color**: sets the background color, if you want to force it, this should be an array of r,g &b, for instance [255, 255, 255] will force the background to be white
* **background_images**: Sets custom user defined images as the captcha background (1 image is selected randomly). It is recommended to turn off all the effects on the image (ignore_all_effects). The full paths to the images must be passed.
* **interpolation**: enable or disable the interpolation on the captcha
* **ignore_all_effects**: Recommended to use when setting background images, will disable all image effects.
Example :
```php
<?php
use Gregwar\CaptchaBundle\Type\CaptchaType;
// ...
$builder->add('captcha', 'captcha', array(
$builder->add('captcha', CaptchaType::class, array(
'width' => 200,
'height' => 50,
'length' => 6,

View File

@ -1,3 +1,3 @@
gregwar_captcha.generate_captcha:
pattern: /generate-captcha/{key}
defaults: { _controller: GregwarCaptchaBundle:Captcha:generateCaptcha }
path: /generate-captcha/{key}
defaults: { _controller: GregwarCaptchaBundle:Captcha:generateCaptcha }

View File

@ -1,24 +1,31 @@
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
- @translator
- '@session'
- '@gregwar_captcha.generator'
- '@translator'
- %gregwar_captcha.config%
tags:
- { 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
- @gregwar_captcha.phrase_builder
- @gregwar_captcha.image_file_handler
- '@router'
- '@gregwar_captcha.captcha_builder'
- '@gregwar_captcha.phrase_builder'
- '@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: Обнови

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1 @@
Bad code value: الرمز غير متطابق

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: Code stimmt nicht überein

View File

@ -0,0 +1 @@
Bad code value: Code does not match

View File

@ -0,0 +1 @@
Bad code value: Code komt niet overeen

View File

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

View File

@ -0,0 +1 @@
Bad code value: Código de verificação inválido

View File

@ -0,0 +1 @@
Bad code value: Kod eşleşmiyor

View File

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

View File

@ -17,4 +17,3 @@
{% endspaceless %}
{% endif %}
{% endblock %}

View File

@ -7,6 +7,7 @@ use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Translation\TranslatorInterface;
@ -22,18 +23,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 +44,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,53 +58,48 @@ 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']
);
$builder->addEventListener(FormEvents::POST_BIND, array($validator, 'validate'));
$event = \Symfony\Component\HttpKernel\Kernel::VERSION >= 2.3 ? FormEvents::POST_SUBMIT : FormEvents::POST_BIND;
$builder->addEventListener($event, array($validator, 'validate'));
}
/**
* @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,34 +113,52 @@ 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)
public function configureOptions(OptionsResolver $resolver)
{
$this->options['mapped'] = false;
$resolver->setDefaults($this->options);
}
/**
* {@inheritdoc}
* BC for SF < 2.7
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}
/**
* @return string
*/
public function getParent()
{
return 'text';
// Not using ::class to support Symfony 2.8 w/ php>=5.3.9
return 'Symfony\Component\Form\Extension\Core\Type\TextType';
}
/**
* @return string
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* @return string
*/
public function getBlockPrefix()
{
return 'captcha';
}

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

@ -17,13 +17,14 @@
}
],
"require": {
"php": ">=5.3.0",
"gregwar/captcha": "v1.0.8"
"php": ">=5.3.9",
"gregwar/captcha": "~1.1",
"symfony/framework-bundle": "~2.1|~3.0",
"symfony/form": "~2.1|~3.0"
},
"autoload": {
"psr-0": {
"Gregwar\\CaptchaBundle": ""
"psr-4": {
"Gregwar\\CaptchaBundle\\": "/"
}
},
"target-dir": "Gregwar/CaptchaBundle"
}
}