User.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\api\validate;
  3. use think\Validate;
  4. class User extends Validate
  5. {
  6. protected $failException = true;
  7. protected $rule = [
  8. 'username' => 'require|regex:^[a-zA-Z][a-zA-Z0-9_]{2,15}$|unique:user',
  9. 'email' => 'email|unique:user',
  10. 'mobile' => 'mobile|unique:user',
  11. 'password' => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
  12. 'captcha' => 'require',
  13. 'captchaId' => 'require',
  14. 'captchaInfo' => 'require',
  15. "openid"=>"require",
  16. "nickname"=>"require"
  17. ];
  18. /**
  19. * 验证场景
  20. */
  21. protected $scene = [
  22. 'login' => ['password', 'captchaId', 'captchaInfo'],
  23. 'register' => ['email', 'username', 'password', 'mobile', 'captcha'],
  24. 'wechat' => [ 'mobile', 'nickname',"openid","unionid"],
  25. ];
  26. public function __construct()
  27. {
  28. $this->field = [
  29. 'username' => __('username'),
  30. 'email' => __('email'),
  31. 'mobile' => __('mobile'),
  32. 'password' => __('password'),
  33. 'captcha' => __('captcha'),
  34. 'captchaId' => __('captchaId'),
  35. 'captchaInfo' => __('captcha'),
  36. ];
  37. $this->message = array_merge($this->message, [
  38. 'username.regex' => __('Please input correct username'),
  39. 'password.regex' => __('Please input correct password')
  40. ]);
  41. parent::__construct();
  42. }
  43. }