| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?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|null 用户逻辑单元 */
- public ?\App\Module\Ulogic\Unit\User $userLogic = null;
- /** @var User|null 用户模型 */
- public ?User $user = null;
- 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);
- }
- }
|