| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Module\User\Validation;
- use App\Module\Ulogic\Validator\Model2UnitValidator;
- use App\Module\User\Models\User;
- use UCore\ValidationCore;
- use App\Module\User\Validator\CanLoginValidator;
- use App\Module\User\Validator\UsernameValidator;
- /**
- * 登录验证器
- *
- */
- class LoginValidation extends ValidationCore
- {
- /**
- * @var \App\Module\Ulogic\Unit\User
- */
- public $userLogic;
- /**
- * 用户模型
- * @var User
- */
- public $user;
- public function rules($rules = []): array
- {
- return [
- [
- 'mobile,password', 'required'
- ],
- [
- 'mobile',
- new UsernameValidator($this),
- 'msg' => '用户名密码错误'
- ],
- [
- 'password', 'passwd', 'msg' => '用户名密码错误2'
- ],
- [
- 'mobile',
- new CanLoginValidator($this),
- 'msg' => '不能登录'
- ],
- [
- 'mobile',
- new Model2UnitValidator($this,['user','userLogic']),
- 'msg' => ''
- ]
- ];
- }
- /**
- * 密码验证
- *
- * @param $passwd
- * @return bool
- */
- public function passwdValidator($passwd): bool
- {
- // dump($passwd,$this->user,password_hash($passwd,PASSWORD_DEFAULT));
- return password_verify($passwd, $this->user->password);
- }
- }
|