User.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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:^(?!.*[&<>"\'\n\r]).{6,32}$|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. ];
  16. /**
  17. * 验证场景
  18. */
  19. protected $scene = [
  20. 'login' => ['password', 'captchaId', 'captchaInfo'],
  21. 'register' => ['email', 'username', 'password', 'mobile', 'captcha'],
  22. ];
  23. public function __construct()
  24. {
  25. $this->field = [
  26. 'username' => __('username'),
  27. 'email' => __('email'),
  28. 'mobile' => __('mobile'),
  29. 'password' => __('password'),
  30. 'captcha' => __('captcha'),
  31. 'captchaId' => __('captchaId'),
  32. 'captchaInfo' => __('captcha'),
  33. ];
  34. $this->message = array_merge($this->message, [
  35. 'username.regex' => __('Please input correct username'),
  36. 'password.regex' => __('Please input correct password')
  37. ]);
  38. parent::__construct();
  39. }
  40. }