Server IP : 185.86.78.101 / Your IP : 216.73.216.124 Web Server : Apache System : Linux 675867-vds-valikoshka1996.gmhost.pp.ua 5.4.0-150-generic #167-Ubuntu SMP Mon May 15 17:35:05 UTC 2023 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /www/wwwroot/mifepriston.org/vendor/yiisoft/yii2/captcha/ |
Upload File : |
<?php /** * @link https://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license https://www.yiiframework.com/license/ */ namespace yii\captcha; use Yii; use yii\base\InvalidConfigException; use yii\helpers\Json; use yii\validators\ValidationAsset; use yii\validators\Validator; /** * CaptchaValidator validates that the attribute value is the same as the verification code displayed in the CAPTCHA. * * CaptchaValidator should be used together with [[CaptchaAction]]. * * Note that once CAPTCHA validation succeeds, a new CAPTCHA will be generated automatically. As a result, * CAPTCHA validation should not be used in AJAX validation mode because it may fail the validation * even if a user enters the same code as shown in the CAPTCHA image which is actually different from the latest CAPTCHA code. * * @author Qiang Xue <qiang.xue@gmail.com> * @since 2.0 */ class CaptchaValidator extends Validator { /** * @var bool whether to skip this validator if the input is empty. */ public $skipOnEmpty = false; /** * @var bool whether the comparison is case sensitive. Defaults to false. */ public $caseSensitive = false; /** * @var string the route of the controller action that renders the CAPTCHA image. */ public $captchaAction = 'site/captcha'; /** * {@inheritdoc} */ public function init() { parent::init(); if ($this->message === null) { $this->message = Yii::t('yii', 'The verification code is incorrect.'); } } /** * {@inheritdoc} */ protected function validateValue($value) { $captcha = $this->createCaptchaAction(); $valid = !is_array($value) && $captcha->validate($value, $this->caseSensitive); return $valid ? null : [$this->message, []]; } /** * Creates the CAPTCHA action object from the route specified by [[captchaAction]]. * @return \yii\captcha\CaptchaAction the action object * @throws InvalidConfigException */ public function createCaptchaAction() { $ca = Yii::$app->createController($this->captchaAction); if ($ca !== false) { /* @var $controller \yii\base\Controller */ list($controller, $actionID) = $ca; $action = $controller->createAction($actionID); if ($action !== null) { return $action; } } throw new InvalidConfigException('Invalid CAPTCHA action ID: ' . $this->captchaAction); } /** * {@inheritdoc} */ public function clientValidateAttribute($model, $attribute, $view) { ValidationAsset::register($view); $options = $this->getClientOptions($model, $attribute); return 'yii.validation.captcha(value, messages, ' . Json::htmlEncode($options) . ');'; } /** * {@inheritdoc} */ public function getClientOptions($model, $attribute) { $captcha = $this->createCaptchaAction(); $code = $captcha->getVerifyCode(false); $hash = $captcha->generateValidationHash($this->caseSensitive ? $code : strtolower($code)); $options = [ 'hash' => $hash, 'hashKey' => 'yiiCaptcha/' . $captcha->getUniqueId(), 'caseSensitive' => $this->caseSensitive, 'message' => Yii::$app->getI18n()->format($this->message, [ 'attribute' => $model->getAttributeLabel($attribute), ], Yii::$app->language), ]; if ($this->skipOnEmpty) { $options['skipOnEmpty'] = 1; } return $options; } }