/** * @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); }
public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $fingerprint = null; if ($options['keep_value'] && $this->session->has($this->key . '_fingerprint')) { $fingerprint = $this->session->get($this->key . '_fingerprint'); } $generator = new CaptchaGenerator($this->generateCaptchaValue(), $options['image_folder'], $options['web_path'], $options['gc_freq'], $options['expiration'], $options['font'], $fingerprint, $options['quality']); if ($options['as_file']) { $captchaCode = $generator->getFile($options['width'], $options['height']); } else { $captchaCode = $generator->getCode($options['width'], $options['height']); } if ($options['keep_value']) { $this->session->set($this->key . '_fingerprint', $generator->getFingerprint()); } $view->addVars(array('captcha_width' => $options['width'], 'captcha_height' => $options['height'], 'captcha_code' => $captchaCode, 'value' => '')); }
public function buildView(FormView $view, FormInterface $form) { $fingerprint = null; if ($this->session->has($this->key . '_fingerprint')) { $fingerprint = $this->session->get($this->key . '_fingerprint'); } $generator = new CaptchaGenerator($this->generateCaptchaValue(), $this->imageFolder, $this->webPath, $this->gcFreq, $this->expiration, $this->font, $fingerprint, $this->quality); if ($this->asFile) { $view->set('captcha_code', $generator->getFile($this->width, $this->height)); } else { $view->set('captcha_code', $generator->getCode($this->width, $this->height)); } $view->set('captcha_width', $this->width); $view->set('captcha_height', $this->height); if ($this->keepValue) { $this->session->set($this->key . '_fingerprint', $generator->getFingerprint()); } $view->set('value', ''); }