78 Commits

Author SHA1 Message Date
3ccfdf1c93 Merge pull request #200 from adamwojs/fix_deprecated_tree_builder_root_call
Fixed deprecated TreeBuilder::root method call in SF 4
2019-09-23 15:07:46 +02:00
b703ed1a0c Merge pull request #201 from adamwojs/fix_deprecated_spacelesss_tag
Removed deprecated spaceless tag
2019-09-23 15:07:20 +02:00
25de43ac90 Removed deprecated spaceless tag 2019-09-22 13:59:41 +02:00
1b4835eb4d Fixed deprecated TreeBuilder::root method call in SF 4 2019-09-22 13:10:16 +02:00
be1ce45060 Merge pull request #196 from ferdynator/master
Fixes deprecation warnings in Symfony 4.2
2019-08-15 18:04:18 +02:00
0f6cd70920 Fixed deprecation warning 2019-01-23 11:01:56 +01:00
754310f488 Fixed deprecation warning 2019-01-23 11:01:17 +01:00
c2d5468556 Merge pull request #172 from cengizhancaliskan/master
Support of multiple instance
2018-11-20 11:41:34 +01:00
980afdc10a Merge pull request #187 from mandalor-development/master
Changed template reference
2018-04-24 11:22:05 +02:00
791128c0fd Changed template reference
According to:
https://symfony.com/doc/current/templating.html#referencing-templates-in-a-bundle

Fixed error:
[critical] Uncaught PHP Exception Twig_Error_Loader: "Unable to find template "GregwarCaptchaBundle::captcha.html.twig" (looked into: /[path]/templates, /[path]/templates, /[path]/vendor/symfony/twig-bridge/Resources/views/Form)." at /[path]/templates/form.html.twig line 17
2018-02-28 15:15:55 +01:00
639430383f Merge pull request #180 from andreybolonin/master
add sf 4.0 support
2017-12-28 12:21:03 +01:00
8e98c5c0ab add public services 2017-12-28 12:30:19 +02:00
539884cd5d add sf 4.0 support 2017-11-27 18:08:24 +02:00
8ce4adb1b1 Adding background_images in persisted options (fixes #175) 2017-10-02 11:12:17 +02:00
b787a8002e Rising default quality to 50 2017-09-27 12:01:02 +02:00
ba9c0e6166 Change session key for as_url option 2017-03-27 22:32:00 +03:00
25b8840f2a Support of multiple instance 2017-03-19 18:40:34 +03:00
045ba7e67e Merge pull request #150 from dprolife/patch-1
Update composer.json
2017-02-23 10:26:22 +01:00
18c85d3a4f donate 2016-10-24 12:05:50 +02:00
f6c45045f0 Adding class captcha_image on the <img> captcha tag (see #160) 2016-09-21 10:36:55 +02:00
f95a951b26 Detail 2016-08-05 20:07:20 +02:00
e1ed228b8b Merge pull request #168 from linnaea/patch-1
Quote parameter references in services.yml
2016-05-30 12:28:28 +02:00
0b3495a081 Quote parameter references in services.yml
Not quoting a scalar starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.
2016-05-28 22:40:00 +08:00
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
1f6c80c326 Update composer.json
Fix symfony requirements
2015-12-17 22:51:31 +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
3d1383e8ae Merge remote-tracking branch 'upstream/master' 2014-09-04 14:04:51 +02:00
798f29e635 Merge remote-tracking branch 'upstream/master'
Conflicts:
	DependencyInjection/Configuration.php
2014-03-19 16:27:04 +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
15 changed files with 156 additions and 77 deletions

View File

@ -2,8 +2,8 @@
namespace Gregwar\CaptchaBundle\Controller; namespace Gregwar\CaptchaBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
@ -11,7 +11,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* *
* @author Jeremy Livingston <jeremy.j.livingston@gmail.com> * @author Jeremy Livingston <jeremy.j.livingston@gmail.com>
*/ */
class CaptchaController extends Controller class CaptchaController extends AbstractController
{ {
/** /**
* Action that is used to generate the captcha, save its code, and stream the image * Action that is used to generate the captcha, save its code, and stream the image
@ -37,7 +37,7 @@ class CaptchaController extends Controller
} }
if (!$isOk) { 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 */ /* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
@ -54,7 +54,29 @@ class CaptchaController extends Controller
$response = new Response($generator->generate($options)); $response = new Response($generator->generate($options));
$response->headers->set('Content-type', 'image/jpeg'); $response->headers->set('Content-type', 'image/jpeg');
$response->headers->set('Pragma', 'no-cache'); $response->headers->set('Pragma', 'no-cache');
$response->headers->set('Cache-Control','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; return $response;
} }

View File

@ -14,8 +14,14 @@ class Configuration implements ConfigurationInterface
*/ */
public function getConfigTreeBuilder() public function getConfigTreeBuilder()
{ {
$treeBuilder = new TreeBuilder(); $treeBuilder = new TreeBuilder('gregwar_captcha');
if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC for symfony/config <= 4.1
$rootNode = $treeBuilder->root('gregwar_captcha'); $rootNode = $treeBuilder->root('gregwar_captcha');
}
$rootNode $rootNode
->addDefaultsIfNotSet() ->addDefaultsIfNotSet()
@ -33,7 +39,7 @@ class Configuration implements ConfigurationInterface
->scalarNode('web_path')->defaultValue('%kernel.root_dir%/../web')->end() ->scalarNode('web_path')->defaultValue('%kernel.root_dir%/../web')->end()
->scalarNode('gc_freq')->defaultValue(100)->end() ->scalarNode('gc_freq')->defaultValue(100)->end()
->scalarNode('expiration')->defaultValue(60)->end() ->scalarNode('expiration')->defaultValue(60)->end()
->scalarNode('quality')->defaultValue(30)->end() ->scalarNode('quality')->defaultValue(50)->end()
->scalarNode('invalid_message')->defaultValue('Bad code value')->end() ->scalarNode('invalid_message')->defaultValue('Bad code value')->end()
->scalarNode('bypass_code')->defaultValue(null)->end() ->scalarNode('bypass_code')->defaultValue(null)->end()
->scalarNode('whitelist_key')->defaultValue('captcha_whitelist_key')->end() ->scalarNode('whitelist_key')->defaultValue('captcha_whitelist_key')->end()
@ -44,7 +50,10 @@ class Configuration implements ConfigurationInterface
->scalarNode('interpolation')->defaultValue(true)->end() ->scalarNode('interpolation')->defaultValue(true)->end()
->arrayNode('text_color')->prototype('scalar')->end()->end() ->arrayNode('text_color')->prototype('scalar')->end()->end()
->arrayNode('background_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('disabled')->defaultValue(false)->end()
->scalarNode('ignore_all_effects')->defaultValue(false)->end()
->scalarNode('session_key')->defaultValue('captcha')->end()
->end() ->end()
; ;

View File

@ -16,7 +16,7 @@ class GregwarCaptchaExtension extends Extension
{ {
/** /**
* @param array $configs * @param array $configs
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container * @param ContainerBuilder $container
*/ */
public function load(array $configs, ContainerBuilder $container) public function load(array $configs, ContainerBuilder $container)
{ {
@ -34,6 +34,6 @@ class GregwarCaptchaExtension extends Extension
$container->setParameter('gregwar_captcha.config.whitelist_key', $config['whitelist_key']); $container->setParameter('gregwar_captcha.config.whitelist_key', $config['whitelist_key']);
$resources = $container->getParameter('twig.form.resources'); $resources = $container->getParameter('twig.form.resources');
$container->setParameter('twig.form.resources', array_merge(array('GregwarCaptchaBundle::captcha.html.twig'), $resources)); $container->setParameter('twig.form.resources', array_merge(array('@GregwarCaptcha/captcha.html.twig'), $resources));
} }
} }

View File

@ -2,7 +2,8 @@
namespace Gregwar\CaptchaBundle\Generator; 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\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Routing\RouterInterface;
@ -18,7 +19,7 @@ use Gregwar\Captcha\PhraseBuilderInterface;
class CaptchaGenerator class CaptchaGenerator
{ {
/** /**
* @var \Symfony\Component\Routing\RouterInterface * @var RouterInterface
*/ */
protected $router; protected $router;
@ -38,12 +39,17 @@ class CaptchaGenerator
protected $imageFileHandler; protected $imageFileHandler;
/** /**
* @param \Symfony\Component\Routing\RouterInterface $router * @param RouterInterface $router
* @param CaptchaBuilderInterface $builder * @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->router = $router;
$this->builder = $builder; $this->builder = $builder;
$this->phraseBuilder = $phraseBuilder; $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 * Get the captcha URL, stream, or filename that will go in the image's src attribute
* *
* @param $key
* @param array $options * @param array $options
* *
* @return array * @return array
@ -71,7 +76,8 @@ class CaptchaGenerator
// Returns the image generation URL // Returns the image generation URL
if ($options['as_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)); return 'data:image/jpeg;base64,' . base64_encode($this->generate($options));
@ -86,7 +92,6 @@ class CaptchaGenerator
} }
/** /**
* @param string $key
* @param array $options * @param array $options
* *
* @return string * @return string
@ -120,6 +125,9 @@ class CaptchaGenerator
$fingerprint = isset($options['fingerprint']) ? $options['fingerprint'] : null; $fingerprint = isset($options['fingerprint']) ? $options['fingerprint'] : null;
$this->builder->setBackgroundImages($options['background_images']);
$this->builder->setIgnoreAllEffects($options['ignore_all_effects']);
$content = $this->builder->build( $content = $this->builder->build(
$options['width'], $options['width'],
$options['height'], $options['height'],
@ -142,7 +150,6 @@ class CaptchaGenerator
} }
/** /**
* @param string $key
* @param array $options * @param array $options
* *
* @return string * @return string

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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,12 +1,19 @@
Gregwar's CaptchaBundle Gregwar's CaptchaBundle
===================== =====================
The `GregwarCaptchaBundle` adds support for a "captcha" form type for the [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YUXRLWHQSWS6L)
Symfony2 form component.
Important note: the master of this repository is containing current development The `GregwarCaptchaBundle` adds support for a captcha form type for the
in order to work with Symfony 2.1. If you are using Symfony 2.0 please checkout Symfony form component.
the 2.0 branch.
It uses [gregwar/captcha](https://github.com/Gregwar/Captcha) as captcha generator, which is a separate standalone library that can be used for none-symfony projects.
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 Installation
============ ============
@ -17,7 +24,15 @@ Ultimately, the GregwarCaptchaBundle files should be downloaded to the
'vendor/bundles/Gregwar/CaptchaBundle' directory. 'vendor/bundles/Gregwar/CaptchaBundle' directory.
You can accomplish this several ways, depending on your personal preference. 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*** ***Using the vendors script***
@ -45,16 +60,6 @@ $ git submodule add git://github.com/Gregwar/CaptchaBundle.git vendor/bundles/Gr
$ git submodule update --init $ 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 ### Step 2: Configure the Autoloader
If you use composer, you can skip this step. If you use composer, you can skip this step.
@ -101,8 +106,11 @@ You can use the "captcha" type in your forms this way:
```php ```php
<?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');
// ... // ...
``` ```
@ -141,14 +149,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 * **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) 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_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 * **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 : Example :
```php ```php
<?php <?php
use Gregwar\CaptchaBundle\Type\CaptchaType;
// ... // ...
$builder->add('captcha', 'captcha', array( $builder->add('captcha', CaptchaType::class, array(
'width' => 200, 'width' => 200,
'height' => 50, 'height' => 50,
'length' => 6, 'length' => 6,

View File

@ -1,3 +1,3 @@
gregwar_captcha.generate_captcha: gregwar_captcha.generate_captcha:
pattern: /generate-captcha/{key} path: /generate-captcha/{key}
defaults: { _controller: GregwarCaptchaBundle:Captcha:generateCaptcha } defaults: { _controller: Gregwar\CaptchaBundle\Controller\CaptchaController::generateCaptchaAction }

View File

@ -7,33 +7,38 @@ parameters:
services: services:
captcha.type: captcha.type:
class: %gregwar_captcha.captcha_type.class% class: '%gregwar_captcha.captcha_type.class%'
public: true
arguments: arguments:
- @session - '@session'
- @gregwar_captcha.generator - '@gregwar_captcha.generator'
- @translator - '@translator'
- %gregwar_captcha.config% - '%gregwar_captcha.config%'
tags: tags:
- { name: form.type, alias: captcha } - { name: form.type, alias: captcha }
gregwar_captcha.generator: gregwar_captcha.generator:
class: %gregwar_captcha.captcha_generator.class% class: '%gregwar_captcha.captcha_generator.class%'
public: true
arguments: arguments:
- @router - '@router'
- @gregwar_captcha.captcha_builder - '@gregwar_captcha.captcha_builder'
- @gregwar_captcha.phrase_builder - '@gregwar_captcha.phrase_builder'
- @gregwar_captcha.image_file_handler - '@gregwar_captcha.image_file_handler'
gregwar_captcha.image_file_handler: gregwar_captcha.image_file_handler:
class: %gregwar_captcha.image_file_handler.class% class: '%gregwar_captcha.image_file_handler.class%'
public: true
arguments: arguments:
- %gregwar_captcha.config.image_folder% - '%gregwar_captcha.config.image_folder%'
- %gregwar_captcha.config.web_path% - '%gregwar_captcha.config.web_path%'
- %gregwar_captcha.config.gc_freq% - '%gregwar_captcha.config.gc_freq%'
- %gregwar_captcha.config.expiration% - '%gregwar_captcha.config.expiration%'
gregwar_captcha.captcha_builder: gregwar_captcha.captcha_builder:
class: %gregwar_captcha.captcha_builder.class% class: '%gregwar_captcha.captcha_builder.class%'
public: true
gregwar_captcha.phrase_builder: gregwar_captcha.phrase_builder:
class: %gregwar_captcha.phrase_builder.class% class: '%gregwar_captcha.phrase_builder.class%'
public: true

View File

@ -0,0 +1 @@
Renew: تجديد

View File

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

View File

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

View File

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

View File

@ -2,8 +2,8 @@
{% if is_human %} {% if is_human %}
- -
{% else %} {% else %}
{% spaceless %} {% apply spaceless %}
<img id="{{ image_id }}" src="{{ captcha_code }}" alt="" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" /> <img class="captcha_image" id="{{ image_id }}" src="{{ captcha_code }}" alt="" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" />
{% if reload %} {% if reload %}
<script type="text/javascript"> <script type="text/javascript">
function reload_{{ image_id }}() { function reload_{{ image_id }}() {
@ -14,7 +14,6 @@
<a class="captcha_reload" href="javascript:reload_{{ image_id }}();">{{ 'Renew'|trans({}, 'gregwar_captcha') }}</a> <a class="captcha_reload" href="javascript:reload_{{ image_id }}();">{{ 'Renew'|trans({}, 'gregwar_captcha') }}</a>
{% endif %} {% endif %}
{{ form_widget(form) }} {{ form_widget(form) }}
{% endspaceless %} {% endapply %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -7,6 +7,7 @@ use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorInterface;
@ -21,6 +22,8 @@ use Gregwar\CaptchaBundle\Generator\CaptchaGenerator;
*/ */
class CaptchaType extends AbstractType class CaptchaType extends AbstractType
{ {
const SESSION_KEY_PREFIX = '_captcha_';
/** /**
* @var SessionInterface * @var SessionInterface
*/ */
@ -64,13 +67,13 @@ class CaptchaType extends AbstractType
$validator = new CaptchaValidator( $validator = new CaptchaValidator(
$this->translator, $this->translator,
$this->session, $this->session,
sprintf('gcb_%s', $builder->getForm()->getName()), sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']),
$options['invalid_message'], $options['invalid_message'],
$options['bypass_code'], $options['bypass_code'],
$options['humanity'] $options['humanity']
); );
$event = \Symfony\Component\HttpKernel\Kernel::VERSION >= 2.3 ? FormEvents::POST_SUBMIT : FormEvents::POST_BIND;
$builder->addEventListener(FormEvents::POST_BIND, array($validator, 'validate')); $builder->addEventListener($event, array($validator, 'validate'));
} }
/** /**
@ -82,7 +85,7 @@ class CaptchaType extends AbstractType
throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information'); 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()); $sessionKey = sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']);
$isHuman = false; $isHuman = false;
if ($options['humanity'] > 0) { if ($options['humanity'] > 0) {
@ -112,7 +115,8 @@ class CaptchaType extends AbstractType
)); ));
$persistOptions = array(); $persistOptions = array();
foreach (array('phrase', 'width', 'height', 'distortion', 'length', 'quality', 'background_color', 'text_color') as $key) { foreach (array('phrase', 'width', 'height', 'distortion', 'length',
'quality', 'background_color', 'background_images', 'text_color') as $key) {
$persistOptions[$key] = $options[$key]; $persistOptions[$key] = $options[$key];
} }
@ -122,24 +126,42 @@ class CaptchaType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setDefaultOptions(OptionsResolverInterface $resolver) public function configureOptions(OptionsResolver $resolver)
{ {
$this->options['mapped'] = false; $this->options['mapped'] = false;
$resolver->setDefaults($this->options); $resolver->setDefaults($this->options);
} }
/**
* {@inheritdoc}
* BC for SF < 2.7
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}
/** /**
* @return string * @return string
*/ */
public function getParent() 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 * @return string
*/ */
public function getName() public function getName()
{
return $this->getBlockPrefix();
}
/**
* @return string
*/
public function getBlockPrefix()
{ {
return 'captcha'; return 'captcha';
} }

View File

@ -17,15 +17,15 @@
} }
], ],
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.3.9",
"gregwar/captcha": "~1.0.12", "gregwar/captcha": "~1.1",
"symfony/framework-bundle": "~2.1", "symfony/framework-bundle": "~2.8|~3.0|~4.0",
"symfony/form": "~2.1" "symfony/form": "~2.8|~3.0|~4.0",
"twig/twig": "^1.40|^2.9"
}, },
"autoload": { "autoload": {
"psr-0": { "psr-4": {
"Gregwar\\CaptchaBundle": "" "Gregwar\\CaptchaBundle\\": "/"
}
} }
},
"target-dir": "Gregwar/CaptchaBundle"
} }