LoginValidation.php 1.5 KB

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