25 Commits

Author SHA1 Message Date
d43cc35eda mise à niveau pour utilisation avec flow 2021-05-28 12:11:05 +02:00
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
1f6c80c326 Update composer.json
Fix symfony requirements
2015-12-17 22:51:31 +01:00
10 changed files with 66 additions and 34 deletions

View File

@ -2,7 +2,7 @@
namespace Gregwar\CaptchaBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@ -11,7 +11,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
*
* @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

View File

@ -14,8 +14,14 @@ class Configuration implements ConfigurationInterface
*/
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
->addDefaultsIfNotSet()
@ -33,7 +39,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 +53,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()
;

View File

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

View File

@ -1,9 +1,13 @@
Gregwar's CaptchaBundle
=====================
[![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)
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
==========================

View File

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

View File

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

View File

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

View File

@ -22,6 +22,8 @@ use Gregwar\CaptchaBundle\Generator\CaptchaGenerator;
*/
class CaptchaType extends AbstractType
{
const SESSION_KEY_PREFIX = '_captcha_';
/**
* @var SessionInterface
*/
@ -65,10 +67,11 @@ 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']
$options['humanity'],
$options['request']
);
$event = \Symfony\Component\HttpKernel\Kernel::VERSION >= 2.3 ? FormEvents::POST_SUBMIT : FormEvents::POST_BIND;
$builder->addEventListener($event, array($validator, 'validate'));
@ -83,7 +86,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 +116,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];
}
@ -126,6 +130,7 @@ class CaptchaType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$this->options['mapped'] = false;
$this->options['request'] = null;
$resolver->setDefaults($this->options);
}

View File

@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Captcha validator
@ -46,6 +47,13 @@ class CaptchaValidator
*/
private $translator;
/**
* Request
*
* @var Request
*/
private $req;
/**
* @param TranslatorInterface $translator
* @param SessionInterface $session
@ -54,7 +62,7 @@ class CaptchaValidator
* @param string $bypassCode
* @param int $humanity
*/
public function __construct(TranslatorInterface $translator, SessionInterface $session, $key, $invalidMessage, $bypassCode, $humanity)
public function __construct(TranslatorInterface $translator, SessionInterface $session, $key, $invalidMessage, $bypassCode, $humanity, Request $req = null)
{
$this->translator = $translator;
$this->session = $session;
@ -62,6 +70,7 @@ class CaptchaValidator
$this->invalidMessage = $invalidMessage;
$this->bypassCode = (string)$bypassCode;
$this->humanity = $humanity;
$this->req = $req;
}
/**
@ -90,10 +99,11 @@ class CaptchaValidator
}
}
if (null == $this->req || 1 < $this->req->get('flow_registration_step')) {
$this->session->remove($this->key);
if ($this->session->has($this->key . '_fingerprint')) {
$this->session->remove($this->key . '_fingerprint');
if ($this->session->has($this->key.'_fingerprint')) {
$this->session->remove($this->key.'_fingerprint');
}
}
}

View File

@ -1,9 +1,9 @@
{
"name": "gregwar/captcha-bundle",
"name": "cadoles/captcha",
"type": "captcha-bundle",
"description": "Captcha bundle",
"keywords": ["symfony2", "captcha", "bot", "visual", "code", "security", "spam"],
"homepage": "https://github.com/Gregwar/CaptchaBundle",
"homepage": "https://github.com/Cadoles/CaptchaBundle",
"license": "MIT",
"authors": [
{
@ -19,8 +19,9 @@
"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",
"twig/twig": "^1.40|^2.9"
},
"autoload": {
"psr-4": {