diff --git a/app/Aspect/Admin/AdminLoginLogAspect.php b/app/Aspect/Admin/AdminLoginLogAspect.php new file mode 100644 index 0000000..26e01dd --- /dev/null +++ b/app/Aspect/Admin/AdminLoginLogAspect.php @@ -0,0 +1,51 @@ +process(); + // 在调用后进行处理 + //todo 登录日志是否需要 + + return $result; + } catch (AdminException $e) { + var_dump($e->getMessage()); + throw new AdminException($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/Request/Admin/LoginRequest.php b/app/Request/Admin/LoginRequest.php index 9c28b96..02a530d 100644 --- a/app/Request/Admin/LoginRequest.php +++ b/app/Request/Admin/LoginRequest.php @@ -22,7 +22,22 @@ class LoginRequest extends FormRequest public function rules(): array { return [ - + 'account' => 'required|digits:11', + 'password' => 'required|string|min:6', ]; } + + public function messages(): array + { + return [ + 'account.required' => '请输入账号', + 'account.digits' => '账号格式错误', + 'password.required' => '请输入密码', + 'password.min' => '密码不能小于6位' + ]; + } + + protected array $scenes = [ + 'login' => ['account', 'password'], + ]; } diff --git a/app/Service/Admin/User/LoginService.php b/app/Service/Admin/User/LoginService.php index d708043..d497acc 100644 --- a/app/Service/Admin/User/LoginService.php +++ b/app/Service/Admin/User/LoginService.php @@ -14,11 +14,9 @@ use App\Constants\Admin\UserCode; use App\Constants\AdminCode; use App\Exception\AdminException; use App\Extend\SystemUtil; -use App\Lib\AdminReturn; use App\Lib\Crypto\CryptoFactory; use App\Model\AdminUser; use App\Service\Admin\BaseService; -use App\Service\Common\AppMakeService; use Exception; use Hyperf\Di\Annotation\Inject; @@ -51,7 +49,9 @@ class LoginService extends BaseService if ($userInfo->status == UserCode::DISABLE) throw new AdminException(UserCode::getMessage($userInfo->status),AdminCode::LOGIN_ERROR); - if ($this->cryptoFactory->cryptoClass('admin-password',$this->request->input('password'),$userInfo->salt) != $userInfo->password) throw new AdminException('密码错误!'); + // pass加密跟数据库做判断 + $password = $this->cryptoFactory->cryptoClass('admin-password',$this->request->input('password'),$userInfo->salt)->encrypt(); + if ($password != $userInfo->password) throw new AdminException('密码错误!'); $userInfo->last_login_time = date('Y-m-d H:i:s'); $userInfo->last_login_ip = SystemUtil::getClientIp(); @@ -59,6 +59,7 @@ class LoginService extends BaseService if (!$userInfo->save()) throw new AdminException('登录失败'); + //生成 token $token = $this->cryptoFactory->cryptoClass('jwt',json_encode([ 'id' => $userInfo->id, 'role' => $userInfo->role_id, diff --git a/config/autoload/middlewares.php b/config/autoload/middlewares.php index 49bdec2..352ccd4 100644 --- a/config/autoload/middlewares.php +++ b/config/autoload/middlewares.php @@ -9,7 +9,11 @@ declare(strict_types=1); * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ + +use Hyperf\Validation\Middleware\ValidationMiddleware; + return [ 'http' => [ + ValidationMiddleware::class ], ];