Adds an option to renew the code (fixes #43)
This commit is contained in:
parent
6b340eb258
commit
35405aca2e
|
@ -28,6 +28,7 @@ class Configuration implements ConfigurationInterface
|
||||||
->scalarNode('charset')->defaultValue('abcdefhjkmnprstuvwxyz23456789')->end()
|
->scalarNode('charset')->defaultValue('abcdefhjkmnprstuvwxyz23456789')->end()
|
||||||
->scalarNode('as_file')->defaultValue(false)->end()
|
->scalarNode('as_file')->defaultValue(false)->end()
|
||||||
->scalarNode('as_url')->defaultValue(false)->end()
|
->scalarNode('as_url')->defaultValue(false)->end()
|
||||||
|
->scalarNode('reload')->defaultValue(false)->end()
|
||||||
->scalarNode('image_folder')->defaultValue('captcha')->end()
|
->scalarNode('image_folder')->defaultValue('captcha')->end()
|
||||||
->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()
|
||||||
|
|
|
@ -33,6 +33,10 @@ class GregwarCaptchaExtension extends Extension
|
||||||
$container->setParameter('gregwar_captcha.config.expiration', $config['expiration']);
|
$container->setParameter('gregwar_captcha.config.expiration', $config['expiration']);
|
||||||
$container->setParameter('gregwar_captcha.config.whitelist_key', $config['whitelist_key']);
|
$container->setParameter('gregwar_captcha.config.whitelist_key', $config['whitelist_key']);
|
||||||
|
|
||||||
|
if ($config['reload'] && !$config['as_url']) {
|
||||||
|
throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information');
|
||||||
|
}
|
||||||
|
|
||||||
$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('GregwarCaptchaBundle::captcha.html.twig'), $resources));
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,6 +133,7 @@ You can define the following configuration options globally or on the CaptchaTyp
|
||||||
* **invalid_message**: error message displayed when an non-matching code is submitted (default="Bad code value", see the translation section for more information)
|
* **invalid_message**: error message displayed when an non-matching code is submitted (default="Bad code value", see the translation section for more information)
|
||||||
* **bypass_code**: code that will always validate the captcha (default=null)
|
* **bypass_code**: code that will always validate the captcha (default=null)
|
||||||
* **whitelist_key**: the session key to use for keep the session keys that can be used for captcha storage, when using as_url (default=captcha_whitelist_key)
|
* **whitelist_key**: the session key to use for keep the session keys that can be used for captcha storage, when using as_url (default=captcha_whitelist_key)
|
||||||
|
* **reload**: adds a link to reload the code
|
||||||
* **humanity**: number of extra forms that the user can submit after a correct validation, if set to a value different of 0, only 1 over (1+humanity) forms will contain a CAPTCHA (default=0, i.e each form will contain the CAPTCHA)
|
* **humanity**: number of extra forms that the user can submit after a correct validation, if set to a value different of 0, only 1 over (1+humanity) forms will contain a CAPTCHA (default=0, i.e each form will contain the CAPTCHA)
|
||||||
|
|
||||||
Example :
|
Example :
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Renew: Renouveler
|
|
@ -3,7 +3,16 @@
|
||||||
-
|
-
|
||||||
{% else %}
|
{% else %}
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
<img src="{{ captcha_code }}" alt="" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" />
|
<img id="{{ id }}" src="{{ captcha_code }}" alt="" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" />
|
||||||
|
{% if reload %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
function reload_{{ id }}() {
|
||||||
|
var img = document.getElementById('{{ id }}');
|
||||||
|
img.src = '{{ captcha_code }}?n=' + (new Date()).getTime();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<a class="captcha_reload" href="javascript:reload_{{ id }}();">{{ 'Renew'|trans({}, 'gregwar_captcha') }}</a>
|
||||||
|
{% endif %}
|
||||||
{{ form_widget(form) }}
|
{{ form_widget(form) }}
|
||||||
{% endspaceless %}
|
{% endspaceless %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -92,6 +92,8 @@ class CaptchaType extends AbstractType
|
||||||
$view->vars = array_merge($view->vars, array(
|
$view->vars = array_merge($view->vars, array(
|
||||||
'captcha_width' => $options['width'],
|
'captcha_width' => $options['width'],
|
||||||
'captcha_height' => $options['height'],
|
'captcha_height' => $options['height'],
|
||||||
|
'reload' => $options['reload'],
|
||||||
|
'id' => uniqid('captcha_'),
|
||||||
'captcha_code' => $this->generator->getCaptchaCode($this->key, $options),
|
'captcha_code' => $this->generator->getCaptchaCode($this->key, $options),
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'is_human' => $isHuman
|
'is_human' => $isHuman
|
||||||
|
|
Loading…
Reference in New Issue