Login4Phone.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Module\User\Validation;
  3. use App\Module\App\Validator\NoLogin;
  4. use App\Module\Common\Validator\Phone;
  5. use App\Module\Sms\Validator\PhoneCode;
  6. use App\Module\Sys\ContinuousTimes;
  7. use App\Module\Ulogic\Validator\Model2Unit;
  8. use App\Module\User\Models\User;
  9. use App\Module\User\Validator\AutoRegPhone;
  10. use App\Module\User\Validator\CanLogin;
  11. use App\Module\User\Validator\LoginJizhi;
  12. use App\Module\User\Validator\PhoneContinuousTimes;
  13. use UCore\ValidationCore;
  14. /**
  15. * 登录验证器
  16. *
  17. */
  18. class Login4Phone extends ValidationCore
  19. {
  20. protected string $name = 'login';
  21. /**
  22. * @var User
  23. */
  24. public $user;
  25. /**
  26. * @var \App\Module\Ulogic\Unit\User
  27. */
  28. public $userLogic;
  29. public function rules($rules = []): array
  30. {
  31. $rules = [
  32. [
  33. 'phone,code', 'required'
  34. ],
  35. [
  36. 'phone',
  37. new \App\Module\Common\Validator\Phone($this),
  38. 'msg' => '不存在的手机号码'
  39. ],
  40. [
  41. 'code', new PhoneCode($this, ['login', 'phone']),
  42. 'msg' => '短信验证码错误'
  43. ],
  44. [
  45. 'phone', new AutoRegPhone($this, ['user']),
  46. 'msg' => '手机号码不可用'
  47. ],
  48. [
  49. 'phone',
  50. new CanLogin($this),
  51. 'msg' => '不能登录'
  52. ],
  53. [
  54. 'phone',new NoLogin($this),
  55. 'msg'=>'重复的登陆,请清空应用储存数据或重新安装后重试'
  56. ],
  57. [
  58. 'phone',
  59. new Model2Unit($this, ['user', 'userLogic']),
  60. 'msg' => ''
  61. ]
  62. ];
  63. // 错误次数验证
  64. $v = new PhoneContinuousTimes($this);
  65. array_unshift($rules,[
  66. 'phone',$v,
  67. 'msg'=>'登录错误过多,限制登录'
  68. ]);
  69. $this->addConsumeErrorValidator($v);
  70. // 登录封禁
  71. $loginJIn = new LoginJizhi($this);
  72. array_unshift($rules,[
  73. 'phone',$loginJIn,
  74. 'msg'=>'登录错误过多,限制登录12小时'
  75. ]);
  76. return parent::rules($rules);
  77. }
  78. }