/** * @param \Symfony\Component\Form\FormView $view * @param \Symfony\Component\Form\FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { if ($options['reload'] && !$options['as_url']) { throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information'); } $sessionKey = sprintf('gcb_%s', $form->getName()); $isHuman = false; if ($options['humanity'] > 0) { $humanityKey = sprintf('%s_humanity', $sessionKey); if ($this->session->get($humanityKey, 0) > 0) { $isHuman = true; } } if ($options['as_url']) { $keys = $this->session->get($options['whitelist_key'], array()); if (!in_array($sessionKey, $keys)) { $keys[] = $sessionKey; } $this->session->set($options['whitelist_key'], $keys); $options['session_key'] = $sessionKey; } $view->vars = array_merge($view->vars, array('captcha_width' => $options['width'], 'captcha_height' => $options['height'], 'reload' => $options['reload'], 'image_id' => uniqid('captcha_'), 'captcha_code' => $this->generator->getCaptchaCode($options), 'value' => '', 'is_human' => $isHuman)); $persistOptions = array(); foreach (array('phrase', 'width', 'height', 'distortion', 'length', 'quality', 'background_color', 'text_color') as $key) { $persistOptions[$key] = $options[$key]; } $this->session->set($sessionKey, $persistOptions); }
/** * @param \Symfony\Component\Form\FormView $view * @param \Symfony\Component\Form\FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { $isHuman = false; if ($options['reload'] && !$options['as_url']) { throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information'); } $session_key = 'gcb_' . $form->getName(); if ($options['humanity'] > 0) { $humanityKey = $session_key . '_humanity'; if ($this->session->get($humanityKey, 0) > 0) { $isHuman = true; } } if ($options['as_url']) { $keys = $this->session->get($options['whitelist_key'], array()); if (!in_array($session_key, $keys)) { $keys[] = $session_key; } $this->session->set($options['whitelist_key'], $keys); $options['session_key'] = $session_key; } $view->vars = array_merge($view->vars, array('captcha_width' => $options['width'], 'captcha_height' => $options['height'], 'reload' => $options['reload'], 'image_id' => uniqid('captcha_'), 'captcha_code' => $this->generator->getCaptchaCode($options), 'value' => '', 'captcha_key' => $session_key, 'is_human' => $isHuman)); $persistOptions = array(); foreach (array('phrase', 'width', 'height', 'distortion', 'length', 'quality', 'whitelist_key', 'bypass_code') as $key) { $persistOptions[$key] = $options[$key]; } $persistOptions['time'] = time(); $persistOptions['ip'] = $this->container->get('request')->getClientIp(); if (!$this->container->getParameter('kernel.debug')) { // $persistOptions['bypass_code'] = null ; } $this->session->set($session_key, $persistOptions); }