12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace app\api\validate;
- use think\Validate;
- class User extends Validate
- {
- protected $failException = true;
- protected $rule = [
- 'username' => 'require|regex:^[a-zA-Z][a-zA-Z0-9_]{2,15}$|unique:user',
- 'email' => 'email|unique:user',
- 'mobile' => 'mobile|unique:user',
- 'password' => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
- 'captcha' => 'require',
- 'captchaId' => 'require',
- 'captchaInfo' => 'require',
- "openid"=>"require|unique:user,openid&unionid",
- "birthday"=>"require|date|dateFormat:Y-m-d",
- "gender"=>"require|number|in:0,1,2",
- "avatar"=>"url",
- "nickname"=>"require",
- "change_email"=>"email",
- "change_mobile"=>"mobile",
- ];
- /**
- * 验证场景
- */
- protected $scene = [
- 'login' => ['password', 'captchaId', 'captchaInfo'],
- 'register' => ['email', 'username', 'password', 'mobile', 'captcha'],
- 'wechat' => ["openid","unionid"],
- 'edit' => ["change_mobile","nickname","change_email","avatar","gender","birthday"],
- ];
- public function __construct()
- {
- $this->field = [
- 'username' => __('username'),
- 'email' => __('email'),
- 'mobile' => __('mobile'),
- 'change_email' => __('email'),
- 'change_mobile' => __('mobile'),
- 'avatar' => __('avatar'),
- 'nickname' => __('nickname'),
- 'gender' => __('gender'),
- 'birthday' => __('birthday'),
- 'password' => __('password'),
- 'captcha' => __('captcha'),
- 'captchaId' => __('captchaId'),
- 'captchaInfo' => __('captcha'),
- ];
- $this->message = array_merge($this->message, [
- 'username.regex' => __('Please input correct username'),
- 'password.regex' => __('Please input correct password')
- ]);
- parent::__construct();
- }
- }
|