Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
d43cc35eda | |||
3ccfdf1c93 | |||
b703ed1a0c | |||
25de43ac90 | |||
1b4835eb4d | |||
be1ce45060 | |||
0f6cd70920 | |||
754310f488 |
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Gregwar\CaptchaBundle\Controller;
|
namespace Gregwar\CaptchaBundle\Controller;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
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
|
||||||
|
@ -14,8 +14,14 @@ class Configuration implements ConfigurationInterface
|
|||||||
*/
|
*/
|
||||||
public function getConfigTreeBuilder()
|
public function getConfigTreeBuilder()
|
||||||
{
|
{
|
||||||
$treeBuilder = new TreeBuilder();
|
$treeBuilder = new TreeBuilder('gregwar_captcha');
|
||||||
$rootNode = $treeBuilder->root('gregwar_captcha');
|
|
||||||
|
if (method_exists($treeBuilder, 'getRootNode')) {
|
||||||
|
$rootNode = $treeBuilder->getRootNode();
|
||||||
|
} else {
|
||||||
|
// BC for symfony/config <= 4.1
|
||||||
|
$rootNode = $treeBuilder->root('gregwar_captcha');
|
||||||
|
}
|
||||||
|
|
||||||
$rootNode
|
$rootNode
|
||||||
->addDefaultsIfNotSet()
|
->addDefaultsIfNotSet()
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
gregwar_captcha.generate_captcha:
|
gregwar_captcha.generate_captcha:
|
||||||
path: /generate-captcha/{key}
|
path: /generate-captcha/{key}
|
||||||
defaults: { _controller: GregwarCaptchaBundle:Captcha:generateCaptcha }
|
defaults: { _controller: Gregwar\CaptchaBundle\Controller\CaptchaController::generateCaptchaAction }
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{% if is_human %}
|
{% if is_human %}
|
||||||
-
|
-
|
||||||
{% else %}
|
{% else %}
|
||||||
{% spaceless %}
|
{% apply spaceless %}
|
||||||
<img class="captcha_image" 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">
|
||||||
@ -14,6 +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 %}
|
||||||
|
@ -70,7 +70,8 @@ class CaptchaType extends AbstractType
|
|||||||
sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']),
|
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'],
|
||||||
|
$options['request']
|
||||||
);
|
);
|
||||||
$event = \Symfony\Component\HttpKernel\Kernel::VERSION >= 2.3 ? FormEvents::POST_SUBMIT : FormEvents::POST_BIND;
|
$event = \Symfony\Component\HttpKernel\Kernel::VERSION >= 2.3 ? FormEvents::POST_SUBMIT : FormEvents::POST_BIND;
|
||||||
$builder->addEventListener($event, array($validator, 'validate'));
|
$builder->addEventListener($event, array($validator, 'validate'));
|
||||||
@ -129,6 +130,7 @@ class CaptchaType extends AbstractType
|
|||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
$this->options['mapped'] = false;
|
$this->options['mapped'] = false;
|
||||||
|
$this->options['request'] = null;
|
||||||
$resolver->setDefaults($this->options);
|
$resolver->setDefaults($this->options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
|||||||
use Symfony\Component\Form\FormError;
|
use Symfony\Component\Form\FormError;
|
||||||
use Symfony\Component\Form\FormEvent;
|
use Symfony\Component\Form\FormEvent;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Captcha validator
|
* Captcha validator
|
||||||
@ -46,6 +47,13 @@ class CaptchaValidator
|
|||||||
*/
|
*/
|
||||||
private $translator;
|
private $translator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request
|
||||||
|
*
|
||||||
|
* @var Request
|
||||||
|
*/
|
||||||
|
private $req;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TranslatorInterface $translator
|
* @param TranslatorInterface $translator
|
||||||
* @param SessionInterface $session
|
* @param SessionInterface $session
|
||||||
@ -54,7 +62,7 @@ class CaptchaValidator
|
|||||||
* @param string $bypassCode
|
* @param string $bypassCode
|
||||||
* @param int $humanity
|
* @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->translator = $translator;
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
@ -62,6 +70,7 @@ class CaptchaValidator
|
|||||||
$this->invalidMessage = $invalidMessage;
|
$this->invalidMessage = $invalidMessage;
|
||||||
$this->bypassCode = (string)$bypassCode;
|
$this->bypassCode = (string)$bypassCode;
|
||||||
$this->humanity = $humanity;
|
$this->humanity = $humanity;
|
||||||
|
$this->req = $req;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,10 +99,11 @@ class CaptchaValidator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->session->remove($this->key);
|
if (null == $this->req || 1 < $this->req->get('flow_registration_step')) {
|
||||||
|
$this->session->remove($this->key);
|
||||||
if ($this->session->has($this->key . '_fingerprint')) {
|
if ($this->session->has($this->key.'_fingerprint')) {
|
||||||
$this->session->remove($this->key . '_fingerprint');
|
$this->session->remove($this->key.'_fingerprint');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "gregwar/captcha-bundle",
|
"name": "cadoles/captcha",
|
||||||
"type": "captcha-bundle",
|
"type": "captcha-bundle",
|
||||||
"description": "Captcha bundle",
|
"description": "Captcha bundle",
|
||||||
"keywords": ["symfony2", "captcha", "bot", "visual", "code", "security", "spam"],
|
"keywords": ["symfony2", "captcha", "bot", "visual", "code", "security", "spam"],
|
||||||
"homepage": "https://github.com/Gregwar/CaptchaBundle",
|
"homepage": "https://github.com/Cadoles/CaptchaBundle",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
@ -20,7 +20,8 @@
|
|||||||
"php": ">=5.3.9",
|
"php": ">=5.3.9",
|
||||||
"gregwar/captcha": "~1.1",
|
"gregwar/captcha": "~1.1",
|
||||||
"symfony/framework-bundle": "~2.8|~3.0|~4.0",
|
"symfony/framework-bundle": "~2.8|~3.0|~4.0",
|
||||||
"symfony/form": "~2.8|~3.0|~4.0"
|
"symfony/form": "~2.8|~3.0|~4.0",
|
||||||
|
"twig/twig": "^1.40|^2.9"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
Reference in New Issue
Block a user