Fixing session key, removing valid_keys which was painful to transport

the whitelist in the session (see #36)
This commit is contained in:
Gregwar
2012-12-04 11:33:54 +01:00
parent 39532390e1
commit 31d080a9b7
7 changed files with 42 additions and 12 deletions

View File

@ -16,6 +16,12 @@ class CaptchaGenerator
*/
protected $session;
/**
* Name of the whitelist key
* @var string
*/
protected $whitelistKey;
/**
* @var \Symfony\Component\Routing\RouterInterface
*/
@ -65,7 +71,7 @@ class CaptchaGenerator
* @param int $gcFreq
* @param int $expiration
*/
public function __construct(SessionInterface $session, RouterInterface $router, $imageFolder, $webPath, $gcFreq, $expiration)
public function __construct(SessionInterface $session, RouterInterface $router, $imageFolder, $webPath, $gcFreq, $expiration, $whitelistKey)
{
$this->session = $session;
$this->router = $router;
@ -73,6 +79,7 @@ class CaptchaGenerator
$this->webPath = $webPath;
$this->gcFreq = $gcFreq;
$this->expiration = $expiration;
$this->whitelistKey = $whitelistKey;
}
/**
@ -96,6 +103,11 @@ class CaptchaGenerator
// Returns the configured URL for image generation
if ($options['as_url']) {
$keys = $this->session->get($this->whitelistKey, array());
if (!in_array($key, $keys)) {
$keys[] = $key;
}
$this->session->set($this->whitelistKey, $keys);
return $this->router->generate('gregwar_captcha.generate_captcha', array('key' => $key));
}