Browse Source

Merge branch 'master' of http://git.bjzxtw.org.cn:3000/zxt/admin_consumer

LiuJ 2 days ago
parent
commit
12e188ca29
2 changed files with 53 additions and 6 deletions
  1. 45 1
      app/Middleware/Auth/FooMiddleware.php
  2. 8 5
      app/Middleware/Auth/SensitiveMiddleware.php

+ 45 - 1
app/Middleware/Auth/FooMiddleware.php

@@ -3,7 +3,8 @@
 declare(strict_types=1);
 
 namespace App\Middleware\Auth;
-
+use App\Controller\LoginController;
+use App\Controller\UserController;
 use Hyperf\Di\Annotation\Inject;
 use Hyperf\HttpServer\Contract\RequestInterface;
 use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse;
@@ -28,6 +29,17 @@ class FooMiddleware implements MiddlewareInterface
      */
     #[Inject]
     private $websiteServiceClient;
+    /**
+     * @var LoginController
+     */
+    #[Inject]
+    protected $loginController;
+
+    /**
+     * @var UserController
+     */
+    #[Inject]
+    protected $userController;
     public function __construct(ContainerInterface $container, HttpResponse $response, RequestInterface $request,Jwt $JWT)
     {
         $this->container = $container;
@@ -73,6 +85,38 @@ class FooMiddleware implements MiddlewareInterface
                         );
                     }
                     Context::set("SiteId",$result['data']['id']);
+                    if($ver['type_id']!=10000){
+                        $userInfo = $this->userController->getUserInfo($ver['uid']);
+                        if($userInfo['code']!=200 && !isset($userInfo['data']) && !empty($userInfo['data']['sszq'])){
+                            $sszq = $userInfo['data']['sszq'];
+                            //组id
+                            $authData = [
+                                'id' => $sszq,
+                                'SiteId' => $result['data']['id']
+                            ];
+                            // 调用 LoginController 中的 checkUserAuth 方法
+                            $resultAuth = $this->loginController->checkUserAuth($authData);
+                            if (!$resultAuth) {
+                                // 如果没有权限,返回错误响应
+                                return $this->response->json(
+                                    [
+                                        'code' => -1,
+                                        'data' => [],
+                                        'message' => '没有权限登陆此网站',
+                                    ]
+                                );
+                            }
+                        }else{
+                            return $this->response->json(
+                                [
+                                    'code' => -1,
+                                    'data' => [],
+                                    'message' => '用户没有群组',
+                                ]
+                            );
+                        }
+
+                    }
                 }
 //                var_dump("中间件:",$ver);
                 Context::set("UserId",$ver['uid']);

+ 8 - 5
app/Middleware/Auth/SensitiveMiddleware.php

@@ -65,11 +65,14 @@ class SensitiveMiddleware implements MiddlewareInterface
 //                    continue;
 //                }
                 if (str_contains($concatenated, $badWord)) {
-                    return $this->response->raw(json_encode([
-                        'code' => 0,
-                        'data' => [],
-                        'message' => '发现违禁词: ' . $badWord
-                    ]));
+                    $message = '发现违禁词: '. $badWord;
+                    return $this->response->json(
+                        [
+                            'code' => 0,
+                            'data' => [$message],
+                            'message' => "该内容存在非法信息,请修改后重新发布"
+                        ]
+                    );
                 }
             }