gregwar / captchabundle Goto Github PK
View Code? Open in Web Editor NEWSymfony bundle implementing a "captcha" form type
License: MIT License
Symfony bundle implementing a "captcha" form type
License: MIT License
I added the captcha on my form with this config
->add("captcha","captcha", array(
'length' => 5,
'height' => 25,
'quality' => 90,
'reload' => true,
'invalid_message' => 'O valor digitado não corresponde com a imagem.'))
when i click renew it does not change the image chrome give me this error
GET data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBl…6qfD2V01FKinypJXu9E7q+urV9G1dLS+9yiiivXPogooooAKKKKAP/2Q==?n=1358825417818
reload_captcha_50fe079ad2592 cadastro:22
(anonymous function)
InjectedScript._evaluateOn
InjectedScript._evaluateAndWrap
InjectedScript.evaluate
if i use as_url i get this error
GET http://localhost/AcheiaVan/web/app_dev.php/generate-captcha/gcb_captcha 404 (Not Found)
i'm confused, but i can not use my custom font, i put file ttf in gregwar/captcha-bundle/gregwar/CaptchaBundle/Generator/Font/
but when i try to get img (as_url used) i've got :
imagettfbbox(): Could not find/open font in /my path/vendor/gregwar/captcha/Gregwar/Captcha/CaptchaBuilder.php line 254
i'm inspect what's happened and found
class (placed in vendor/gregwar/captcha/Gregwar/Captcha)CaptchaBuilder->build() at line 321 Builder looking for FONTS in Captcha folder, not in CaptchaBundle..
It's seems strange(i installed bundle and i put font file in Bundle dir)
Hello,
I'm trying to validate captcha with an ajax request and allways with the same response, the form is invalid. Do you know how to do this?
Sorry for my english.
Regards
$criteria = sprintf('>= now - %s minutes', $this->expiration);
Here you select files that new, but must select old files. And there is no implementation for "minutes" but "minute".
So the string must be:
$criteria = sprintf('<= now - %s minute', $this->expiration);
Also I think bundle in a future must provide ability to:
Thank you for your bundle.
Add empty ALT to captcha image to make it pass HTML5 validator. An ALT attribute is always required for an image. If no alternative text has to be displayed, then this must be empty. Another option would be to put purely "captcha"
Ignore character case, when comparing captcha-codes. Adding strtolower() to niceize() in class CaptchaValidator would do it.
hello,
can you configure the bundle to be appropriate with "composer"
Hi,
I would like to use this bundle but i can't install it.
I copied the bundle manually on the repertory vendor\bundles\Gregwar\CaptchaBundle
I added the namespace in autoload.php: 'Gregwar' => DIR.'/../vendor/bundles',
I added the bundle in AppKernel.php: new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
I had the configuration line in config.yml: gregwar_captcha: ~
But the aplication can't load the resource config.yml because of the line gregwar_captcha: ~
Any idea?
Please provide an option to disable captcha (for example to use in dev environment, or in debug)
Hi. I have this issue on SF 2.0.12.
Catchable Fatal Error: Argument 1 passed to Gregwar\CaptchaBundle\Type\CaptchaType::__construct() must be an instance of Symfony\Component\HttpFoundation\Session\Session, instance of Symfony\Component\HttpFoundation\Session given, called in /home/pchludzinski/www/d7/Symfony/app/cache/dev/appDevDebugProjectContainer.php on line 234 and defined in /home/pchludzinski/www/d7/Symfony/vendor/bundles/Gregwar/CaptchaBundle/Type/CaptchaType.php line 37
Captcha distortion still well recognized
Need to increase the degree of distortion or allow to control the degree of distortion in the configuration files
Perhaps this article will help a bit
Hy!
I'm use the CaptchaBundle and I need customize the error message.
Thanks
The new loaded image is not displaying (probably wrong path?).
Hi,
Bundle works fine except from the two options: charset and quality.
When I try to use one of them I get: The option "quality" does not exist 500 Internal Server Error - CreationException
Here is my configuration:
->add('captcha', 'captcha', array(
'width' => 200,
'height' => 50,
'length' => 6,
'as_file' => true,
'quality' => 30,
))
Any ideas what can be wrong?
BTW. There should be also and 'errorMessage' option to customize error message.
In Form Theming section:
{% block captcha_widget %}
{% spaceless %}
<img src="{{ captcha_code }}" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" />
{{ form_widget(form) }}
{% spaceless %} // It must be "endspaceless"
{% endblock %}
Anyway, I like this bundle very much. Nice job :).
Hello, I have follow the readme instructions and I havent been able to show up the image in my PROD enviroment. Locally is working correctly, but in my prod server is not showing up the images.
I have as_ulr = true.
Added the routing in my routing.yml
And in my security.yml I added the exception to allouw acces to the route.
In my config I have the as
gregwar_captcha:
as_url: true
But still I am getting the same result.
Cheers.
If the captcha-code was not correct, do not keep the old value in the textfield of the reloaded form.
I thought we could create another repository which would only contain the generation logic and be Symfony-independant
This could be done easily by splitting the CaptchaGenerator
class, and creating a CaptchaGeneratorService
for instance which would inherits from the generator and add Symfony specific logic
@jeremylivingston: what do you think?
I'll wait for your changes to avoid painful conflicts and I think I will work on this
Increase image quality for better readability:
Hi,
I just installed the bundle according to the readme, using Composer, in Symfony 2.1.0 RC1, and I'm getting this error:
Fatal error: Declaration of Gregwar\CaptchaBundle\Type\CaptchaType::buildView() must be compatible with that of Symfony\Component\Form\FormTypeInterface::buildView() in [...]/vendor/gregwar/captcha-bundle/Gregwar/CaptchaBundle/Type/CaptchaType.php on line 122
I read that this is the error you get when you installed the master branch in Symfony 2.0.x, but I'm definitely running a brand new install of Symfony 2.1 and I added "gregwar/captcha-bundle": "1.0.0"
to composer.json.
Do I miss something?
Thanks you,
Philippe
Thanks you for this bundle.
I have to override the bundle to implement arithmetic captcha ( 3+ 13 ) = ?. Is there any easy way to do this ?
Fatal error: Declaration of Gregwar\CaptchaBundle\Type\CaptchaType::buildForm() must be compatible with that of Symfony\Component\Form\FormTypeInterface::buildForm() in D:\Proyectos\symfony\vendor\bundles\Gregwar\CaptchaBundle\Type\CaptchaType.php on line 122
Gregwar\CaptchaBundle\Type\CaptchaType.php
<?php
namespace Gregwar\CaptchaBundle\Type;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormViewInterface;
use Gregwar\CaptchaBundle\Validator\CaptchaValidator;
use Gregwar\CaptchaBundle\Generator\CaptchaGenerator;
use Gregwar\CaptchaBundle\DataTransformer\EmptyTransformer;
/**
* Captcha type
*
* @author Gregwar <[email protected]>
*/
class CaptchaType e xtends AbstractType
{
/**
* Options
* @var array
*/
private $options = array();
/**
* Session key
* @var string
*/
private $key = 'captcha';
public function __construct(Session $session, $config)
{
$this->session = $session;
$this->options = $config;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->key = $builder->getForm()->getName();
$builder->addValidator(
new CaptchaValidator($this->session, $this->key)
);
}
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{
$fingerprint = null;
if ($options['keep_value'] && $this->session->has($this->key.'_fingerprint')) {
$fingerprint = $this->session->get($this->key.'_fingerprint');
}
$generator = new CaptchaGenerator($this->generateCaptchaValue(),
$options['image_folder'],
$options['web_path'],
$options['gc_freq'],
$options['expiration'],
$options['font'],
$fingerprint,
$options['quality']);
if ($options['as_file']) {
$captchaCode = $generator->getFile($options['width'], $options['height']);
} else {
$captchaCode = $generator->getCode($options['width'], $options['height']);
}
if ($options['keep_value']) {
$this->session->set($this->key.'_fingerprint', $generator->getFingerprint());
}
$view->addVars(array(
'captcha_width' => $options['width'],
'captcha_height' => $options['height'],
'captcha_code' => $captchaCode,
' value' => '',
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->options['property_path'] = false;
$resolver->setDefaults($this->options);
}
public function getParent()
{
return 'text';
}
public function getName()
{
return 'captcha';
}
private function generateCaptchaValue()
{
if (!$this->options['keep_value'] || !$this->session->has($this->key)) {
$value = '';
$chars = str_split($this->options['charset']);
for ($i=0; $i<$this->options['length']; $i++) {
$value.= $chars[array_rand($chars)];
}
$this->session->set($this->key, $value);
} else {
$value = $this->session->get($this->key);
}
return $value;
}
}
Symfony\Component\Form\FormTypeInterface.php
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form;
interface FormTypeInterface
{
/**
* Builds the form.
*
* This method gets called for each type in the hierarchy starting form the
* top most type.
* Type extensions can further modify the form.
*
* @see FormTypeExtensionInterface::buildForm()
*
* @param FormBuilder $builder The form builder
* @param array $options The options
*/
function buildForm(FormBuilder $builder, array $options);
/**
* Builds the form view.
*
* This method gets called for each type in the hierarchy starting form the
* top most type.
* Type extensions can further modify the view.
*
* @see FormTypeExtensionInterface::buildView()
*
* @param FormView $view The view
* @param FormInterface $form The form
*/
function buildView(FormView $view, FormInterface $form);
/**
* Builds the form view.
*
* This method gets called for each type in the hierarchy starting form the
* top most type.
* Type extensions can further modify the view.
*
* Children views have been built when this method gets called so you get
* a chance to modify them.
*
* @see FormTypeExtensionInterface::buildViewBottomUp()
*
* @param FormView $view The view
* @param FormInterface $form The form
*/
function buildViewBottomUp(FormView $view, FormInterface $form);
/**
* Returns a builder for the current type.
*
* The builder is retrieved by going up in the type hierarchy when a type does
* not provide one.
*
* @param string $name The name of the builder
* @param FormFactoryInterface $factory The form factory
* @param array $options The options
*
* @return FormBuilder|null A form builder or null when the type does not have a builder
*/
function createBuilder($name, FormFactoryInterface $factory, array $options);
/**
* Returns the default options for this type.
*
* @param array $options
*
* @return array The default options
*/
function getDefaultOptions(array $options);
/**
* Returns the allowed option values for each option (if any).
*
* @param array $options
*
* @return array The allowed option values
*/
function getAllowedOptionValues(array $options);
/**
* Returns the name of the parent type.
*
* @param array $options
*
* @return string|null The name of the parent type if any otherwise null
*/
function getParent(array $options);
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
function getName();
/**
* Adds extensions for this type.
*
* @param array $extensions An array of FormTypeExtensionInterface
*
* @throws UnexpectedTypeException if any extension does not implement FormTypeExtensionInterface
*/
function setExtensions(array $extensions);
/**
* Returns the extensions associated with this type.
*
* @return array An array of FormTypeExtensionInterface
*/
function getExtensions();
}
UsuarioType.php
<?php
namespace usuario\UsuarioBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class UsuarioType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('nombre','text', array('label' => 'Nombres'));
$builder->add('apellido','text', array('label' => 'Apellidos'));
$builder->add('company','text', array('label' => 'Compañía'));
$builder->add('cargo','text', array('label' => 'Cargo'));
$builder->add('email', 'email');
$builder->add('captcha', 'captcha', array(
'label' => 'Eres humano? pruebalo, escribe los caracteres que veas en la imagen',
));
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'usuario\UsuarioBundle\Entity\Usuario',
);
}
public function getName()
{
return 'usuario';
}
}
$builder
->add('name', 'text', array(
'required' => true,
'label' => 'Your Name'
))
->add('email', 'email', array(
'required' => true,
'label' => 'Your Email'
))
->add('message', 'textarea', array(
'required' => true,
'label' => 'Your Message',
))
->add('captcha', 'captcha', array(
'label' => 'Enter Captcha',
'required' => false,
'invalid_message' => 'The captcha code is invalid.'
));
This is my form. When I fill all field and submit, no error is found. But form is invalid.
When I remove captcha field, and fill then submit. Form is valid.
Can you tell me what issue happens ?
Hi folks, I'm on this issue since 2 days and i'm really stuck! Here is the thing.
There is a simple "sign-up" form which use the captcha type.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', 'email', [
'label' => 'all.email'
])
->add('plainPassword', 'repeated', [
'type' => 'password',
'invalid_message' => 'all.password_mismatch',
'first_options' => ['label' => 'all.password'],
'second_options' => ['label' => 'all.password_confirm']
])
->add('captcha', 'captcha')
->add('submit', 'submit', [
'label' => 'all.submit'
])
;
}
Using my Apache Web Server, everything is fine. When I type a bad captcha I got insulted, when I type a good one my account is created.
Using the PHP built-in web server app/console server:run
I always get insulted!
Using Apache, I've figured out the following workflow:
Using PHP Web Server:
Any ideas?
Thanks.
The "arguments" injection in the services.yml file is really getting bigger and bigger, it should be cleaner
The ida of splitting logic was to extract the logic into another repo, in order to be able to use it for other purpose/framework than Sf2
Gregwar\Captcha
? Gregwar\CaptchaBuilder
?
Can you tag your releases so that users can keep up to date without relying on dev-mater?
Thanks!
I want to specify the validation group in which the capture must be validated. Usualy I do this via a constraint. How can I do this using the captcha?
Hello,
when I open multiple tabs in a browser, only the last captcha value is valid. It seems like that captcha codes and tokens (probably!) are stored in session without any identification key.
Thanks for your attention.
$builder->add('captcha', 'captcha', array(
'required' => false,
'width' => 220,
'height' => 50,
'length' => 8,
'keep_value' => false,
'as_url' => true,
'reload' => true,
'invalid_message' => 'The captcha code is invalid.'
));
Here, I am setting the length to 8, as_url and reload to true as I want to provide a link to reload captcha. But, it defaults to 5. It works when as_url and reload are false, though. Am I doing something wrong? Btw, it is really great bundle. Thanks.
It would be great to have the possibility to add a link below the input field to renew the captcha image through an AJAX call, just in case the user does not understand the first image.
The configuration should also be transported in the session IMO
Hi, i'm on a single page application as front and Sf 2.4 as backend. I'm not using sf form.. how can i use this bundle without using sf form?
Fatal error: Declaration of Gregwar\CaptchaBundle\Type\CaptchaType::getDefaultOptions() must be compatible with that of Symfony\Component\Form\FormTypeInterface::getDefaultOptions() in /home/animalsmc/domains/animals-mc.com/public_html/Symfony/vendor/bundles/Gregwar/CaptchaBundle/Type/CaptchaType.php on line 119
And i am aware i have to use the 2.0 brach, but can you please note in the docs how to do it ?
Because i use sf2 2.0.15 i use the deps file, so how do i tell it to take the 2.0 branch ?
I followed the steps, and for the second time (I just assumed I had miss something the first one, now I do want to know what I am missing), I am getting this: Fatal error: Call to undefined function Gregwar\CaptchaBundle\Generator\imagecreatetruecolor() in […]
. Any idea?
fix for the changes in sf 2.1 forms : https://github.com/symfony/symfony/blob/master/UPGRADE-2.1.md
Index: vendor/gregwar/captcha-bundle/Gregwar/CaptchaBundle/Type/CaptchaType.php
===================================================================
--- vendor/gregwar/captcha-bundle/Gregwar/CaptchaBundle/Type/CaptchaType.php (revision )
+++ vendor/gregwar/captcha-bundle/Gregwar/CaptchaBundle/Type/CaptchaType.php (revision )
@@ -81,7 +81,7 @@
$view->set('value', '');
}
- public function getDefaultOptions(array $options = array())
+ public function getDefaultOptions()
{
$this->options = array_replace($this->options, $options);
$this->options['property_path'] = false;
I have installed the captcha bundle and it awsom. Just when I enter a wrong code in the captcha the invalid message is not rendering when submiting the form.
Any idea what can it be.
Cheers and great job.
In symfony 2.2 "Bad code value" remains untranslated. Symfony 2.2 ignores translations for validator.
What if I need background colour to be immutable? For example I want only white background for captcha. Can you help me with option?
Once you've copied a CAPTCHA, if you did a mistake on a form, it's really painful to copy it again and again
Maybe we could add an option to consider that an user is an human once he typed a correct CAPTCHA, this would be an int telling how many form can be submitted after each captcha (humanity
?)
if submitted form is invalid, but captcha is valid - do not validate captcha (and do not render) on next submits while form is invalid
Hi,
I've just implemented this bundle in an app of mine. I noticed that the paged rendering was significantly slower, so I did some profiling: http://imgur.com/T82ibjr
The image distortion is very expensive. I did some load testing on a real server and here are the results :
With distortion (blue: number of clients, green: load time): http://imgur.com/rAUXG0P
Without distortion (blue: number of clients, green: load time): http://imgur.com/ZtWvzaE
The load time is stable without distortion, but it's really not scalable with distortion enabled.
I'm using quite big captchas with hight jpeg quality:
gregwar_captcha:
quality: 60
background_color: [217, 237, 248]
height: 90
width: 260
charset: abcdefhjkmnptuvwxy234689
Is that a known issue? Do you have any idea on how this could be improved?
Keeping the captcha value between two requests should be configurable
Can we create a Github service hook for this repository as detailed here?
https://packagist.org/about
It would be nice to start tagging versions of this repository and creating development branches as well. Adding this service hook will allow these updates to be pulled automatically.
Please let me know if you have questions. Thanks!
If you are using Varnish Memcahe ESI or other hell's cache, we need this small fix in widget render, that's needed for using as_url option( GET requests cache problem):
{% block captcha_widget %}
.....
< img id="{{ image_id }}" sr c="{{ captcha_code }}?n={{random() }}" alt="" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" />
Font should be configurable
Charset used should be configurable
Hello, I'm currently using Gregwar Captcha Bundle for my registration form. Now I've added it to another form (contact form). The problem is that when I try to submit the registration form, it's not accepting the captcha shown as correct, because the captcha is used one more time, after registration form.
I have a page, where I have Registration on every page + Contact form on every page. So any ideas are welcome.
an additional: color_text option needed! i saw pull request for merge commit in other ticket, but i fetch Bundle yesterday, and this options does not exist(probably merge are not completed)
builder->addEventListener(FormEvents::POST_SUBMIT(instead POST_BIND/BIND), array($validator, 'validate'));
I'am using your Bundle and it works perfectly! But as I come to writing unit tests for my forms I ran into this error:
# phpunit -c app/phpunit.xml.dist src/Acme/AcmeBundle/Tests/Form/
PHPUnit 3.7.19 by Sebastian Bergmann.
The Xdebug extension is not loaded. No code coverage will be generated.
..E
Time: 1 second, Memory: 12.50Mb
There was 1 error:
1) Acme\AcmeBundle\Test\Form\Type\ContactTypeTest::testSubmitData with
data set #0 (array('Peter', 'nice!', 'nice!', 'test'))
Symfony\Component\Form\Exception\InvalidArgumentException: Could not load type "
captcha"
Is there a way to make this Bundle work in the test envoirement?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.