|
|
@ -2,6 +2,7 @@ |
|
|
|
namespace Wiggins\MyProject; |
|
|
|
|
|
|
|
use yii\base\Model; |
|
|
|
use yii\validators\Validator; |
|
|
|
|
|
|
|
/** |
|
|
|
* UserInput类是用于用户登录或注册场景中输入数据 |
|
|
@ -62,19 +63,33 @@ |
|
|
|
public function rules() |
|
|
|
{ |
|
|
|
return[ |
|
|
|
//用户名长度
|
|
|
|
['name','string','length'=>[3,20],'message'=>'用户名长度为3至20个字符'], |
|
|
|
//邮件格式
|
|
|
|
['email','email'], |
|
|
|
//密码格式
|
|
|
|
['password','string','length'=>[3,10]], |
|
|
|
//确认密码与密码需一直
|
|
|
|
['pwdConfirm','compare','compareAttribute'=>'password','message'=>'两次密码必须一致'], |
|
|
|
//注册场景
|
|
|
|
[['name','email','password','pwdConfirm'],'required','on'=>'register'], |
|
|
|
//登录场景
|
|
|
|
[['name','password'],'required','on'=>'login'], |
|
|
|
[['name','email'],'Wiggins\MyProject\MyValidator'] |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* MyValidator类用于独立验证器 |
|
|
|
* @author kuangweijian <867034892@qq.com> |
|
|
|
* @since 1.0.0 |
|
|
|
*/ |
|
|
|
class MyValidator extends Validator |
|
|
|
{ |
|
|
|
public function validateAttribute($model, $attribute) |
|
|
|
{ |
|
|
|
$blackList='kuangweijian'; |
|
|
|
$ret = in_array($blackList, $model->attributes); |
|
|
|
if($ret){ |
|
|
|
$this->addError($model, $attribute,"{$blackList}属于黑名单人员"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
?>
|