CaptchaAction is used together with Captcha and CaptchaValidator to provide the CAPTCHA feature. By configuring the properties of CaptchaAction, you may customize the appearance of the generated CAPTCHA images, such as the font color, the background color, etc. Note that CaptchaAction requires either GD2 extension or ImageMagick PHP extension. Using CAPTCHA involves the following steps: 1. Override [[\yii\web\Controller::actions()]] and register an action of class CaptchaAction with ID 'captcha' 2. In the form model, declare an attribute to store user-entered verification code, and declare the attribute to be validated by the 'captcha' validator. 3. In the controller view, insert a Captcha widget in the form.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\base\Action
コード例 #1
0
ファイル: CaptchaAction.php プロジェクト: singleso/singleso
 public function validate($input, $caseSensitive)
 {
     // Skip validation on AJAX requests, as it expires the captcha.
     if (Yii::$app->request->isAjax) {
         return true;
     }
     return parent::validate($input, $caseSensitive);
 }
コード例 #2
0
 /**
  * @inheritdoc
  * 
  * Creates the default cache component if it is not provided.
  */
 public function init()
 {
     parent::init();
     $this->controllerNamespace = 'jlorente\\captcha';
     $this->setAliases(['@captchaRoute' => '/' . $this->getUniqueId() . '/captcha/index']);
     if (empty($this->cache)) {
         $this->setCache(['class' => ApcCache::className(), 'keyPrefix' => 'captcha_']);
     }
     if (empty($this->captchaAction)) {
         $this->captchaAction = ['class' => CaptchaAction::className(), 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null];
     }
 }
コード例 #3
0
 protected function generateVerifyCode()
 {
     if ($this->isDigital) {
         if ($this->minLength > $this->maxLength) {
             $this->maxLength = $this->minLength;
         }
         if ($this->minLength < 3) {
             $this->minLength = 3;
         }
         if ($this->maxLength > 20) {
             $this->maxLength = 20;
         }
         $length = mt_rand($this->minLength, $this->maxLength);
         $code = '';
         for ($i = 0; $i < $length; $i++) {
             $code .= mt_rand(0, 9);
         }
         return $code;
     }
     return parent::generateVerifyCode();
 }
コード例 #4
0
ファイル: Module.php プロジェクト: nordsoftware/yii2-account
 /**
  * Initializes the class map.
  */
 protected function initClassMap()
 {
     $this->classMap = ArrayHelper::merge([self::CLASS_ACCOUNT => Account::className(), self::CLASS_TOKEN => AccountToken::className(), self::CLASS_PROVIDER => AccountProvider::className(), self::CLASS_LOGIN_HISTORY => AccountLoginHistory::className(), self::CLASS_PASSWORD_HISTORY => AccountPasswordHistory::className(), self::CLASS_LOGIN_FORM => LoginForm::className(), self::CLASS_PASSWORD_FORM => PasswordForm::className(), self::CLASS_SIGNUP_FORM => SignupForm::className(), self::CLASS_CONNECT_FORM => ConnectForm::className(), self::CLASS_FORGOT_PASSWORD_FORM => ForgotPasswordForm::className(), self::CLASS_WEB_USER => User::className(), self::CLASS_CAPTCHA => Captcha::className(), self::CLASS_CAPTCHA_ACTION => CaptchaAction::className(), self::CLASS_PASSWORD_BEHAVIOR => PasswordAttributeBehavior::className(), self::CLASS_PASSWORD_VALIDATOR => PasswordStrengthValidator::className()], $this->classMap);
 }
コード例 #5
0
 /**
  * Renders the CAPTCHA image.
  * @param string $code the verification code
  * @return string image contents
  */
 protected function renderImage($code)
 {
     // alphabets ?
     if (!$this->useMbChars) {
         return parent::renderImage($code);
     }
     // font defaults to seto-mini.ttf
     if ($this->mbFontFile === null) {
         $this->mbFontFile = __DIR__ . DIRECTORY_SEPARATOR . 'seto-mini.ttf';
     }
     $encoding = 'UTF-8';
     if (Captcha::checkRequirements() === 'gd') {
         // check if conversion to Shift_JIS is needed
         $gd_info = gd_info();
         if ($gd_info['JIS-mapped Japanese Font Support']) {
             $code = mb_convert_encoding($code, 'SJIS', 'UTF-8');
             $encoding = 'SJIS';
         }
         return $this->mbRenderImageByGD($code, $encoding);
     } else {
         return $this->mbRenderImageByImagick($code, $encoding);
     }
 }
コード例 #6
0
 public function actions()
 {
     return ['captcha' => ['class' => CaptchaAction::className()]];
 }
コード例 #7
0
ファイル: DefaultController.php プロジェクト: cjq/QRCode-yii2
 /**
  * @inheritdoc
  */
 public function actions()
 {
     return ['error' => ['class' => ErrorAction::className()], 'about' => ['class' => ViewAction::className(), 'defaultView' => 'about'], 'captcha' => ['class' => CaptchaAction::className(), 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, 'backColor' => 0xf5f5f5, 'height' => 34]];
 }
コード例 #8
0
 public function actions()
 {
     return ['captcha' => ['class' => CaptchaAction::className(), 'minLength' => 7, 'maxLength' => 7]];
 }
コード例 #9
0
ファイル: CaptchaAction.php プロジェクト: tsyrya/mybriop
 public function __construct($id, $controller, $config = [])
 {
     $fontFile = '@app/components/captcha/gtw.ttf';
     $config = ArrayHelper::merge(compact('fontFile'), $config);
     parent::__construct($id, $controller, $config);
 }
コード例 #10
0
ファイル: SiteController.php プロジェクト: Araused/GaServer
 public function actions()
 {
     return ['error' => ['class' => ErrorAction::className()], 'captcha' => ['class' => CaptchaAction::className(), 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null]];
 }