54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-10-30
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\components;
|
|
|
|
use yii\captcha\CaptchaAction;
|
|
|
|
class ResetCaptchaAction extends CaptchaAction
|
|
{
|
|
public function __construct($id, $controller, $config = [])
|
|
{
|
|
$this->minLength = 4;
|
|
$this->maxLength = 4;
|
|
$this->padding = 2;
|
|
$this->offset = 8;
|
|
$this->fontFile = '@app/web/statics/font/MarkerFelt.ttc';
|
|
$this->height = 36;
|
|
parent::__construct($id, $controller, $config);
|
|
}
|
|
|
|
public function generateVerifyCode()
|
|
{
|
|
if ($this->minLength > $this->maxLength) {
|
|
$this->maxLength = $this->minLength;
|
|
}
|
|
$length = mt_rand($this->minLength, $this->maxLength);
|
|
|
|
$letters = '2345678bcefhjkmnprsuvwxyz';
|
|
$code = '';
|
|
$max = strlen($letters) - 1;
|
|
for ($i = 0; $i < $length; ++$i) {
|
|
$code .= $letters[mt_rand(0, $max)];
|
|
}
|
|
|
|
return mt_rand(0, 1) ? $code : strtoupper($code);
|
|
}
|
|
|
|
public function validate($input, $caseSensitive)
|
|
{
|
|
// 测试环境下忽略验证码
|
|
if(YII_ENV_DEV || YII_ENV_TEST) {
|
|
return true;
|
|
}
|
|
return parent::validate($input, $caseSensitive);
|
|
}
|
|
} |