mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-05-10 10:54:27 +08:00
1. 维护代码健壮
2. 更新项目结构文档
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user