Exemplo n.º 1
0
 /**
  * The given $value is valid if it is an array of format array(hash:string, phrase:string) and the hash was derived from the entered phrase
  * 
  * @param mixed $value The value that should be validated
  * @return void
  */
 protected function isValid($value)
 {
     if (!($this->options["ignoreWhenLoggedIn"] && $this->securityContext->getAccount())) {
         if (is_array($value)) {
             if (empty($value["hash"]) || empty($value["phrase"])) {
                 $this->addError("Malformed array given; expected array(hash:string, phrase:string)", 422526241);
             } else {
                 if ($this->captchaService->validatePhrase($value["phrase"], $value["hash"]) !== true) {
                     $this->addError("Given captcha phrase mismatches the hash", 422526242);
                 }
             }
         } else {
             $this->addError("This argument must be an array", 422526240);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Renders the captcha image and its textfields
  *
  * @return string
  */
 public function render()
 {
     // Render image tag
     $this->tag->reset();
     $this->tag->setTagName("img");
     $this->tag->addAttributes($this->getAttributes("image", array("src" => $this->captchaService->create($this->arguments["width"], $this->arguments["height"]), "width" => $this->arguments["width"], "height" => $this->arguments["height"], "style" => "width: " . $this->arguments["width"] . "px; height: " . $this->arguments["height"] . "px;")));
     $markup = str_replace("{image}", $this->tag->render(), $this->arguments["markup"]);
     // Render phrase textfield
     $this->tag->reset();
     $this->tag->setTagName("input");
     $this->tag->addAttributes($this->getAttributes("phrase", array("name" => $this->arguments["name"] . "[phrase]", "type" => "text", "autocomplete" => "off")));
     $markup = str_replace("{phrase}", $this->tag->render(), $markup);
     // Render phrase textfield
     $this->tag->reset();
     $this->tag->setTagName("input");
     $this->tag->addAttributes($this->getAttributes("hash", array("name" => $this->arguments["name"] . "[hash]", "type" => "hidden", "value" => $this->captchaService->getPhraseHash())));
     return str_replace("{hash}", $this->tag->render(), $markup);
 }