/**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     try {
         $this->recaptcha->checkAnswer($this->request->server->get('REMOTE_ADDR'), $this->request->get($this->recaptcha->getChallengeField()), $this->request->get($this->recaptcha->getResponseField()));
     } catch (Exception $e) {
         $this->context->addViolation($constraint->message);
     }
 }
Beispiel #2
0
 /**
  * @covers \Recaptcher\Recaptcha::getServerUrl
  * @covers \Recaptcher\Recaptcha::getChallengeUrl
  * @covers \Recaptcher\Recaptcha::getIFrameUrl
  * @covers \Recaptcher\Recaptcha::getWidgetHtml
  */
 public function testGetWidgetHtml()
 {
     $recaptcha = new Recaptcha('123', '321');
     // options
     $options = array('theme' => 'red');
     $this->assertNotSame(false, strpos($recaptcha->getWidgetHtml($options), '<script type="text/javascript">var RecaptchaOptions = ' . json_encode($options)));
     // challenge url with lang
     $this->assertNotSame(false, strpos($recaptcha->getWidgetHtml(array('lang' => 'ru')), '<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=123&hl=ru"'));
     // iframe url
     $this->assertNotSame(false, strpos($recaptcha->getWidgetHtml(), '<iframe src="http://www.google.com/recaptcha/api/noscript?k=123"'));
 }