Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
c2d5468556 | |||
980afdc10a | |||
791128c0fd | |||
639430383f | |||
8e98c5c0ab | |||
539884cd5d | |||
8ce4adb1b1 | |||
b787a8002e | |||
ba9c0e6166 | |||
25b8840f2a | |||
045ba7e67e | |||
18c85d3a4f | |||
f6c45045f0 | |||
f95a951b26 | |||
e1ed228b8b | |||
0b3495a081 | |||
53c25b2e9a | |||
fcf8c4fd01 | |||
1f6c80c326 |
@ -33,7 +33,7 @@ class Configuration implements ConfigurationInterface
|
||||
->scalarNode('web_path')->defaultValue('%kernel.root_dir%/../web')->end()
|
||||
->scalarNode('gc_freq')->defaultValue(100)->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('bypass_code')->defaultValue(null)->end()
|
||||
->scalarNode('whitelist_key')->defaultValue('captcha_whitelist_key')->end()
|
||||
@ -47,6 +47,7 @@ class Configuration implements ConfigurationInterface
|
||||
->arrayNode('background_images')->prototype('scalar')->end()->end()
|
||||
->scalarNode('disabled')->defaultValue(false)->end()
|
||||
->scalarNode('ignore_all_effects')->defaultValue(false)->end()
|
||||
->scalarNode('session_key')->defaultValue('captcha')->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
|
@ -34,6 +34,6 @@ class GregwarCaptchaExtension extends Extension
|
||||
$container->setParameter('gregwar_captcha.config.whitelist_key', $config['whitelist_key']);
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
Gregwar's CaptchaBundle
|
||||
=====================
|
||||
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YUXRLWHQSWS6L)
|
||||
|
||||
The `GregwarCaptchaBundle` adds support for a captcha form type for the
|
||||
Symfony form component.
|
||||
|
||||
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
|
||||
==========================
|
||||
|
||||
|
@ -7,17 +7,19 @@ parameters:
|
||||
|
||||
services:
|
||||
captcha.type:
|
||||
class: %gregwar_captcha.captcha_type.class%
|
||||
class: '%gregwar_captcha.captcha_type.class%'
|
||||
public: true
|
||||
arguments:
|
||||
- '@session'
|
||||
- '@gregwar_captcha.generator'
|
||||
- '@translator'
|
||||
- %gregwar_captcha.config%
|
||||
- '%gregwar_captcha.config%'
|
||||
tags:
|
||||
- { name: form.type, alias: captcha }
|
||||
|
||||
gregwar_captcha.generator:
|
||||
class: %gregwar_captcha.captcha_generator.class%
|
||||
class: '%gregwar_captcha.captcha_generator.class%'
|
||||
public: true
|
||||
arguments:
|
||||
- '@router'
|
||||
- '@gregwar_captcha.captcha_builder'
|
||||
@ -25,15 +27,18 @@ services:
|
||||
- '@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:
|
||||
- %gregwar_captcha.config.image_folder%
|
||||
- %gregwar_captcha.config.web_path%
|
||||
- %gregwar_captcha.config.gc_freq%
|
||||
- %gregwar_captcha.config.expiration%
|
||||
- '%gregwar_captcha.config.image_folder%'
|
||||
- '%gregwar_captcha.config.web_path%'
|
||||
- '%gregwar_captcha.config.gc_freq%'
|
||||
- '%gregwar_captcha.config.expiration%'
|
||||
|
||||
gregwar_captcha.captcha_builder:
|
||||
class: %gregwar_captcha.captcha_builder.class%
|
||||
class: '%gregwar_captcha.captcha_builder.class%'
|
||||
public: true
|
||||
|
||||
gregwar_captcha.phrase_builder:
|
||||
class: %gregwar_captcha.phrase_builder.class%
|
||||
class: '%gregwar_captcha.phrase_builder.class%'
|
||||
public: true
|
||||
|
@ -3,7 +3,7 @@
|
||||
-
|
||||
{% else %}
|
||||
{% 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 %}
|
||||
<script type="text/javascript">
|
||||
function reload_{{ image_id }}() {
|
||||
|
@ -22,6 +22,8 @@ use Gregwar\CaptchaBundle\Generator\CaptchaGenerator;
|
||||
*/
|
||||
class CaptchaType extends AbstractType
|
||||
{
|
||||
const SESSION_KEY_PREFIX = '_captcha_';
|
||||
|
||||
/**
|
||||
* @var SessionInterface
|
||||
*/
|
||||
@ -53,7 +55,7 @@ class CaptchaType extends AbstractType
|
||||
{
|
||||
$this->session = $session;
|
||||
$this->generator = $generator;
|
||||
$this->translator = $translator;
|
||||
$this->translator = $translator;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
@ -65,7 +67,7 @@ class CaptchaType extends AbstractType
|
||||
$validator = new CaptchaValidator(
|
||||
$this->translator,
|
||||
$this->session,
|
||||
sprintf('gcb_%s', $builder->getForm()->getName()),
|
||||
sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']),
|
||||
$options['invalid_message'],
|
||||
$options['bypass_code'],
|
||||
$options['humanity']
|
||||
@ -83,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');
|
||||
}
|
||||
|
||||
$sessionKey = sprintf('gcb_%s', $form->getName());
|
||||
$sessionKey = sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']);
|
||||
$isHuman = false;
|
||||
|
||||
if ($options['humanity'] > 0) {
|
||||
@ -113,7 +115,8 @@ class CaptchaType extends AbstractType
|
||||
));
|
||||
|
||||
$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];
|
||||
}
|
||||
|
||||
@ -151,6 +154,14 @@ class CaptchaType extends AbstractType
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getBlockPrefix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'captcha';
|
||||
}
|
||||
|
@ -19,8 +19,8 @@
|
||||
"require": {
|
||||
"php": ">=5.3.9",
|
||||
"gregwar/captcha": "~1.1",
|
||||
"symfony/framework-bundle": "~2.1|~3.0",
|
||||
"symfony/form": "~2.1|~3.0"
|
||||
"symfony/framework-bundle": "~2.8|~3.0|~4.0",
|
||||
"symfony/form": "~2.8|~3.0|~4.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
Reference in New Issue
Block a user