LoginValidation.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Module\User\Validation;
  3. use App\Module\Ulogic\Validator\Model2Unit;
  4. use App\Module\User\Models\User;
  5. use UCore\ValidationCore;
  6. use App\Module\User\Validator\CanLogin;
  7. use App\Module\User\Validator\Username;
  8. /**
  9. * 登录验证器
  10. *
  11. */
  12. class LoginValidation extends ValidationCore
  13. {
  14. /**
  15. * @var \App\Module\Ulogic\Unit\User
  16. */
  17. public $userLogic;
  18. /**
  19. * 用户模型
  20. * @var User
  21. */
  22. public $user;
  23. public function rules($rules = []): array
  24. {
  25. return [
  26. [
  27. 'mobile,password', 'required'
  28. ],
  29. [
  30. 'mobile',
  31. new Username($this),
  32. 'msg' => '用户名密码错误'
  33. ],
  34. [
  35. 'password', 'passwd', 'msg' => '用户名密码错误2'
  36. ],
  37. [
  38. 'mobile',
  39. new CanLogin($this),
  40. 'msg' => '不能登录'
  41. ],
  42. [
  43. 'mobile',
  44. new Model2Unit($this,['user','userLogic']),
  45. 'msg' => ''
  46. ]
  47. ];
  48. }
  49. /**
  50. * 密码验证
  51. *
  52. * @param $passwd
  53. * @return bool
  54. */
  55. public function passwdValidator($passwd): bool
  56. {
  57. // dump($passwd,$this->user,password_hash($passwd,PASSWORD_DEFAULT));
  58. return password_verify($passwd, $this->user->password);
  59. }
  60. }