Admin.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\admin\validate;
  3. use think\Validate;
  4. class Admin extends Validate
  5. {
  6. protected $failException = true;
  7. protected $rule = [
  8. 'username' => 'require|regex:^[a-zA-Z][a-zA-Z0-9_]{2,15}$|unique:admin',
  9. 'nickname' => 'require',
  10. 'password' => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
  11. 'email' => 'email|unique:admin',
  12. 'mobile' => 'mobile|unique:admin',
  13. 'group_arr' => 'require|array',
  14. ];
  15. /**
  16. * 验证提示信息
  17. * @var array
  18. */
  19. protected $message = [];
  20. /**
  21. * 字段描述
  22. */
  23. protected $field = [
  24. ];
  25. /**
  26. * 验证场景
  27. */
  28. protected $scene = [
  29. 'add' => ['username', 'nickname', 'password', 'email', 'mobile', 'group_arr'],
  30. ];
  31. /**
  32. * 验证场景-前台自己修改自己资料
  33. */
  34. public function sceneInfo()
  35. {
  36. return $this->only(['nickname', 'password', 'email', 'mobile'])
  37. ->remove('password', 'require');
  38. }
  39. /**
  40. * 验证场景-编辑资料
  41. */
  42. public function sceneEdit()
  43. {
  44. return $this->only(['username', 'nickname', 'password', 'email', 'mobile', 'group_arr'])
  45. ->remove('password', 'require');
  46. }
  47. public function __construct()
  48. {
  49. $this->field = [
  50. 'username' => __('Username'),
  51. 'nickname' => __('Nickname'),
  52. 'password' => __('Password'),
  53. 'email' => __('Email'),
  54. 'mobile' => __('Mobile'),
  55. 'group_arr' => __('Group Name Arr'),
  56. ];
  57. $this->message = array_merge($this->message, [
  58. 'username.regex' => __('Please input correct username'),
  59. 'password.regex' => __('Please input correct password')
  60. ]);
  61. parent::__construct();
  62. }
  63. }