Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
6a147a2ea3
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Gregwar\CaptchaBundle\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ class CaptchaController extends Controller
|
|||
}
|
||||
|
||||
if (!$isOk) {
|
||||
throw $this->createNotFoundException('Unable to generate a captcha via an URL with this session key.');
|
||||
return $this->error($options);
|
||||
}
|
||||
|
||||
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
|
||||
|
@ -54,7 +54,29 @@ class CaptchaController extends Controller
|
|||
$response = new Response($generator->generate($options));
|
||||
$response->headers->set('Content-type', 'image/jpeg');
|
||||
$response->headers->set('Pragma', 'no-cache');
|
||||
$response->headers->set('Cache-Control','no-cache');
|
||||
$response->headers->set('Cache-Control', 'no-cache');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty image with status code 428 Precondition Required
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
protected function error($options)
|
||||
{
|
||||
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
|
||||
$generator = $this->container->get('gregwar_captcha.generator');
|
||||
$generator->setPhrase('');
|
||||
|
||||
$response = new Response($generator->generate($options));
|
||||
$response->setStatusCode(428);
|
||||
$response->headers->set('Content-type', 'image/jpeg');
|
||||
$response->headers->set('Pragma', 'no-cache');
|
||||
$response->headers->set('Cache-Control', 'no-cache');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class GregwarCaptchaExtension extends Extension
|
|||
{
|
||||
/**
|
||||
* @param array $configs
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
namespace Gregwar\CaptchaBundle\Generator;
|
||||
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Gregwar\Captcha\CaptchaBuilder;
|
||||
use Gregwar\Captcha\PhraseBuilder;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
|
@ -18,7 +19,7 @@ use Gregwar\Captcha\PhraseBuilderInterface;
|
|||
class CaptchaGenerator
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\Routing\RouterInterface
|
||||
* @var RouterInterface
|
||||
*/
|
||||
protected $router;
|
||||
|
||||
|
@ -38,12 +39,17 @@ class CaptchaGenerator
|
|||
protected $imageFileHandler;
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\Routing\RouterInterface $router
|
||||
* @param RouterInterface $router
|
||||
* @param CaptchaBuilderInterface $builder
|
||||
* @param ImageFileHandlerInterface $imageFileHandler
|
||||
* @param PhraseBuilderInterface $phraseBuilder
|
||||
* @param ImageFileHandler $imageFileHandler
|
||||
*/
|
||||
public function __construct(RouterInterface $router, CaptchaBuilderInterface $builder, PhraseBuilderInterface $phraseBuilder, ImageFileHandler $imageFileHandler)
|
||||
{
|
||||
public function __construct(
|
||||
RouterInterface $router,
|
||||
CaptchaBuilderInterface $builder,
|
||||
PhraseBuilderInterface $phraseBuilder,
|
||||
ImageFileHandler $imageFileHandler
|
||||
) {
|
||||
$this->router = $router;
|
||||
$this->builder = $builder;
|
||||
$this->phraseBuilder = $phraseBuilder;
|
||||
|
@ -53,7 +59,6 @@ class CaptchaGenerator
|
|||
/**
|
||||
* Get the captcha URL, stream, or filename that will go in the image's src attribute
|
||||
*
|
||||
* @param $key
|
||||
* @param array $options
|
||||
*
|
||||
* @return array
|
||||
|
@ -86,7 +91,6 @@ class CaptchaGenerator
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
|
@ -148,7 +152,6 @@ class CaptchaGenerator
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) <2011-2013> Grégoire Passault
|
||||
Copyright (c) <2011-2015> Grégoire Passault
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Renew: Оновити
|
|
@ -0,0 +1 @@
|
|||
Bad code value: Невірний код
|
|
@ -60,7 +60,7 @@ class CaptchaValidator
|
|||
$this->session = $session;
|
||||
$this->key = $key;
|
||||
$this->invalidMessage = $invalidMessage;
|
||||
$this->bypassCode = $bypassCode;
|
||||
$this->bypassCode = (string)$bypassCode;
|
||||
$this->humanity = $humanity;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ class CaptchaValidator
|
|||
}
|
||||
}
|
||||
|
||||
if (!($code && is_string($code) && ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) {
|
||||
if (!($code !== null && is_string($code) && ($this->compare($code, $expectedCode) || $this->compare($code, $this->bypassCode)))) {
|
||||
$form->addError(new FormError($this->translator->trans($this->invalidMessage, array(), 'validators')));
|
||||
} else {
|
||||
if ($this->humanity > 0) {
|
||||
|
@ -159,6 +159,6 @@ class CaptchaValidator
|
|||
*/
|
||||
protected function compare($code, $expectedCode)
|
||||
{
|
||||
return ($expectedCode && is_string($expectedCode) && $this->niceize($code) == $this->niceize($expectedCode));
|
||||
return ($expectedCode !== null && is_string($expectedCode) && $this->niceize($code) == $this->niceize($expectedCode));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,13 @@
|
|||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"gregwar/captcha": "~1.0.11",
|
||||
"gregwar/captcha": "~1.1",
|
||||
"symfony/framework-bundle": "~2.1",
|
||||
"symfony/form": "~2.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Gregwar\\CaptchaBundle": ""
|
||||
"psr-4": {
|
||||
"Gregwar\\CaptchaBundle\\": "/"
|
||||
}
|
||||
}
|
||||
},
|
||||
"target-dir": "Gregwar/CaptchaBundle"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue