1. 维护代码健壮

2. 更新项目结构文档
This commit is contained in:
技术老胡
2026-04-27 16:20:41 +08:00
parent 9a16a88640
commit 0e5de50337
198 changed files with 21038 additions and 702 deletions

View File

@@ -2,6 +2,7 @@
namespace app\http\admin\middleware;
use app\exception\UnauthorizedException;
use app\service\system\access\AdminAuthService;
use support\Context;
use Webman\Http\Request;
@@ -34,6 +35,7 @@ class AdminAuthMiddleware implements MiddlewareInterface
* @param Request $request 请求对象
* @param callable $handler handler
* @return Response 响应对象
* @throws UnauthorizedException
*/
public function process(Request $request, callable $handler): Response
{
@@ -42,11 +44,7 @@ class AdminAuthMiddleware implements MiddlewareInterface
if ($token === '') {
if ((int) env('AUTH_MIDDLEWARE_STRICT', 1) === 1) {
return json([
'code' => 401,
'msg' => 'admin unauthorized',
'data' => null,
]);
throw new UnauthorizedException('管理员未授权');
}
} else {
$admin = $this->adminAuthService->authenticateToken(
@@ -55,11 +53,7 @@ class AdminAuthMiddleware implements MiddlewareInterface
$request->header('user-agent', '')
);
if (!$admin) {
return json([
'code' => 401,
'msg' => 'admin unauthorized',
'data' => null,
]);
throw new UnauthorizedException('管理员未授权');
}
Context::set('auth.admin_id', (int) $admin->id);