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

@ -25,6 +25,12 @@ class CaptchaType extends AbstractType
*/
protected $session;
/**
* The session key
* @var string
*/
protected $key = null;
/**
* @var \Gregwar\CaptchaBundle\Generator\CaptchaGenerator
*/
@ -54,9 +60,11 @@ class CaptchaType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->key = 'gcb_'.$builder->getForm()->getName();
$validator = new CaptchaValidator(
$this->session,
$builder->getForm()->getName(),
$this->key,
$options['invalid_message'],
$options['bypass_code']
);
@ -74,7 +82,7 @@ class CaptchaType extends AbstractType
$view->vars = array_merge($view->vars, array(
'captcha_width' => $options['width'],
'captcha_height' => $options['height'],
'captcha_code' => $this->generator->getCaptchaCode($form->getName(), $options),
'captcha_code' => $this->generator->getCaptchaCode($this->key, $options),
'value' => '',
));
}
@ -103,4 +111,4 @@ class CaptchaType extends AbstractType
{
return 'captcha';
}
}
}