Advertisement
Guest User

unzend.com_332

a guest
Oct 8th, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.88 KB | None | 0 0
  1. <?php
  2. // Ioncube Decoder Unzend.Com Email unzend@gmail.com
  3. // http://www.unzend.com
  4. /**
  5.  * CCaptchaValidator class file.
  6.  *
  7.  * @author Qiang Xue <qiang.xue@gmail.com>
  8.  * @link http://www.yiiframework.com/
  9.  * @copyright 2008-2013 Yii Software LLC
  10.  * @license http://www.yiiframework.com/license/
  11.  */
  12.  
  13. /**
  14.  * CCaptchaValidator validates that the attribute value is the same as the verification code displayed in the CAPTCHA.
  15.  *
  16.  * CCaptchaValidator should be used together with {@link CCaptchaAction}.
  17.  *
  18.  * @author Qiang Xue <qiang.xue@gmail.com>
  19.  * @package system.validators
  20.  * @since 1.0
  21.  */
  22. class CCaptchaValidator extends CValidator
  23. {
  24.     /**
  25.      * @var boolean whether the comparison is case sensitive. Defaults to false.
  26.      */
  27.     public $caseSensitive=false;
  28.     /**
  29.      * @var string ID of the action that renders the CAPTCHA image. Defaults to 'captcha',
  30.      * meaning the 'captcha' action declared in the current controller.
  31.      * This can also be a route consisting of controller ID and action ID.
  32.      */
  33.     public $captchaAction='captcha';
  34.     /**
  35.      * @var boolean whether the attribute value can be null or empty.
  36.      * Defaults to false, meaning the attribute is invalid if it is empty.
  37.      */
  38.     public $allowEmpty=false;
  39.  
  40.     /**
  41.      * Validates the attribute of the object.
  42.      * If there is any error, the error message is added to the object.
  43.      * @param CModel $object the object being validated
  44.      * @param string $attribute the attribute being validated
  45.      */
  46.     protected function validateAttribute($object,$attribute)
  47.     {
  48.         $value=$object->$attribute;
  49.         if($this->allowEmpty && $this->isEmpty($value))
  50.             return;
  51.         $captcha=$this->getCaptchaAction();
  52.         // reason of array checking is explained here: https://github.com/yiisoft/yii/issues/1955
  53.         if(is_array($value) || !$captcha->validate($value,$this->caseSensitive))
  54.         {
  55.             $message=$this->message!==null?$this->message:Yii::t('yii','The verification code is incorrect.');
  56.             $this->addError($object,$attribute,$message);
  57.         }
  58.     }
  59.  
  60.     /**
  61.      * Returns the CAPTCHA action object.
  62.      * @throws CException if {@link action} is invalid
  63.      * @return CCaptchaAction the action object
  64.      * @since 1.1.7
  65.      */
  66.     protected function getCaptchaAction()
  67.     {
  68.         if(($captcha=Yii::app()->getController()->createAction($this->captchaAction))===null)
  69.         {
  70.             if(strpos($this->captchaAction,'/')!==false) // contains controller or module
  71.             {
  72.                 if(($ca=Yii::app()->createController($this->captchaAction))!==null)
  73.                 {
  74.                     list($controller,$actionID)=$ca;
  75.                     $captcha=$controller->createAction($actionID);
  76.                 }
  77.             }
  78.             if($captcha===null)
  79.                 throw new CException(Yii::t('yii','CCaptchaValidator.action "{id}" is invalid. Unable to find such an action in the current controller.',
  80.                         array('{id}'=>$this->captchaAction)));
  81.         }
  82.         return $captcha;
  83.     }
  84.  
  85.     /**
  86.      * Returns the JavaScript needed for performing client-side validation.
  87.      * @param CModel $object the data object being validated
  88.      * @param string $attribute the name of the attribute to be validated.
  89.      * @return string the client-side validation script.
  90.      * @see CActiveForm::enableClientValidation
  91.      * @since 1.1.7
  92.      */
  93.     public function clientValidateAttribute($object,$attribute)
  94.     {
  95.         $captcha=$this->getCaptchaAction();
  96.         $message=$this->message!==null ? $this->message : Yii::t('yii','The verification code is incorrect.');
  97.         $message=strtr($message, array(
  98.             '{attribute}'=>$object->getAttributeLabel($attribute),
  99.         ));
  100.         $code=$captcha->getVerifyCode(false);
  101.         $hash=$captcha->generateValidationHash($this->caseSensitive ? $code : strtolower($code));
  102.         $js="
  103. var hash = jQuery('body').data('{$this->captchaAction}.hash');
  104. if (hash == null)
  105.     hash = $hash;
  106. else
  107.     hash = hash[".($this->caseSensitive ? 0 : 1)."];
  108. for(var i=value.length-1, h=0; i >= 0; --i) h+=value.".($this->caseSensitive ? '' : 'toLowerCase().')."charCodeAt(i);
  109. if(h != hash) {
  110.     messages.push(".CJSON::encode($message).");
  111. }
  112. ";
  113.  
  114.         if($this->allowEmpty)
  115.         {
  116.             $js="
  117. if(jQuery.trim(value)!='') {
  118.     $js
  119. }
  120. ";
  121.         }
  122.  
  123.         return $js;
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement