Account.php 1.4 KB

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