fixed uncached 404
This commit is contained in:
parent
d6c6de0f83
commit
909d1a3773
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
namespace Gregwar\CaptchaBundle\Controller;
|
namespace Gregwar\CaptchaBundle\Controller;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,8 +36,9 @@ class CaptchaController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!$isOk) {
|
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 */
|
/* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator $generator */
|
||||||
|
@ -58,4 +59,26 @@ class CaptchaController extends Controller
|
||||||
|
|
||||||
return $response;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue