1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace app\admin\validate;
- use think\Validate;
- class Admin extends Validate
- {
- protected $failException = true;
- protected $rule = [
- 'username' => 'require|regex:^[a-zA-Z][a-zA-Z0-9_]{2,15}$|unique:admin',
- 'nickname' => 'require',
- 'password' => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
- 'email' => 'email|unique:admin',
- 'mobile' => 'mobile|unique:admin',
- 'group_arr' => 'require|array',
- 'openid' => 'require|unique:admin,openid^unionid',
- 'change_mobile' => 'require|mobile',
- 'change_email' => 'email',
- ];
- /**
- * 验证提示信息
- * @var array
- */
- protected $message = [];
- /**
- * 字段描述
- */
- protected $field = [
- ];
- /**
- * 验证场景
- */
- protected $scene = [
- 'add' => ['username', 'nickname', 'password', 'email', 'mobile', 'group_arr'],
- 'wechat' => ['opendid',"unionid"]
- ];
- /**
- * 验证场景-前台自己修改自己资料
- */
- public function sceneInfo()
- {
- return $this->only(['nickname', 'password', 'email', 'mobile'])
- ->remove('password', 'require');
- }
- public function sceneWxEdit(){
- return $this->only(["nickname","change_mobile","change_email","avatar"]);
- }
- /**
- * 验证场景-编辑资料
- */
- public function sceneEdit()
- {
- return $this->only(['username', 'nickname', 'password', 'email', 'mobile', 'group_arr'])
- ->remove('password', 'require');
- }
- public function __construct()
- {
- $this->field = [
- 'username' => __('Username'),
- 'nickname' => __('Nickname'),
- 'password' => __('Password'),
- 'email' => __('Email'),
- 'change_email' => __('Email'),
- 'mobile' => __('Mobile'),
- 'change_mobile' => __('Mobile'),
- 'group_arr' => __('Group Name Arr'),
- ];
- $this->message = array_merge($this->message, [
- 'username.regex' => __('Please input correct username'),
- 'password.regex' => __('Please input correct password')
- ]);
- parent::__construct();
- }
- }
|