Ejemplo n.º 1
0
 /**
  * Run action
  */
 public function run()
 {
     if (!extension_loaded('mbstring')) {
         throw new CHttpException(500, Yii::t('main', 'Missing extension "{ext}"', array('{ext}' => 'mbstring')));
     }
     // set font file with all extended UTF-8 characters
     // Duality supplied with the framework does not support some extended characters like ščťžôäě...
     $this->fontFile = dirname(__FILE__) . '/fonts/nimbus.ttf';
     // set captcha mode
     $this->mode = strtolower($this->mode);
     // set image size
     switch ($this->mode) {
         case self::MODE_LOGICAL:
         case self::MODE_WORDS:
             $this->width = 300;
             $this->height = 50;
             break;
         case self::MODE_MATHVERBAL:
             $this->width = 400;
             $this->height = 50;
             break;
         case self::MODE_MATH:
         case self::MODE_DEFAULT:
         default:
             $this->width = 120;
             $this->height = 50;
     }
     if ($this->mode == self::MODE_DEFAULT) {
         // default framework implementation
         parent::run();
     } else {
         // we hash result value rather than the displayed code
         if (isset($_GET[self::REFRESH_GET_VAR])) {
             $result = $this->getVerifyResult(true);
             echo CJSON::encode(array('hash1' => $this->generateValidationHash($result), 'hash2' => $this->generateValidationHashCI($result), 'url' => $this->getController()->createUrl($this->getId(), array('v' => uniqid()))));
         } else {
             $this->renderImage($this->getVerifyCode());
         }
     }
     Yii::app()->end();
 }