作者 lyh

gx

@@ -32,6 +32,7 @@ class LoginAuthMiddleware @@ -32,6 +32,7 @@ class LoginAuthMiddleware
32 return response(['code'=> Code::USER_LOGIN_ERROE,'msg'=>'当前用户被禁用']); 32 return response(['code'=> Code::USER_LOGIN_ERROE,'msg'=>'当前用户被禁用']);
33 } 33 }
34 } 34 }
  35 + //TODO::查看当前角色是否被禁用
35 return $next($request); 36 return $next($request);
36 } 37 }
37 } 38 }
@@ -26,17 +26,56 @@ class LoginAuthMiddleware @@ -26,17 +26,56 @@ class LoginAuthMiddleware
26 if(empty($info) || empty($token)){ 26 if(empty($info) || empty($token)){
27 return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户未登录']); 27 return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户未登录']);
28 } 28 }
  29 + $role_info = $this->setRole($info);
  30 + //获取当前操作的控制器与方法
  31 + $action = $request->route()->getAction();
  32 + //查询当前用户是否拥有权限操作
  33 + $this->viewOperateAuth($role_info,$action);
  34 + //配置数据库
  35 + $this->setProject($info);
  36 + return $next($request);
  37 + }
  38 +
  39 + /**
  40 + * @remark :设置数据库
  41 + * @name :setProject
  42 + * @author :lyh
  43 + * @method :post
  44 + * @time :2023/7/28 14:52
  45 + */
  46 + public function setProject($info){
29 // 设置数据信息 47 // 设置数据信息
30 $project = ProjectServer::useProject($info['project_id']); 48 $project = ProjectServer::useProject($info['project_id']);
31 if(empty($project)){ 49 if(empty($project)){
32 return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'数据库未配置']); 50 return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'数据库未配置']);
33 } 51 }
  52 + }
  53 +
  54 + /**
  55 + * @remark :查看角色权限
  56 + * @name :setRole
  57 + * @author :lyh
  58 + * @method :post
  59 + * @time :2023/7/28 14:53
  60 + */
  61 + public function setRole($info){
34 //操作权限设置 62 //操作权限设置
35 $projectRoleModel = new ProjectRoleModel(); 63 $projectRoleModel = new ProjectRoleModel();
36 $role_info = $projectRoleModel->read(['id'=>$info['role_id']]); 64 $role_info = $projectRoleModel->read(['id'=>$info['role_id']]);
37 - //获取当前操作的控制器与方法  
38 - $action = $request->route()->getAction();  
39 - //查询当前用户是否拥有权限操作 65 + if($role_info['status'] != 0){
  66 + return response(['code'=>Code::USER_LOGIN_ERROE,'当前用户角色被禁用']);
  67 + }
  68 + return $role_info;
  69 + }
  70 +
  71 + /**
  72 + * @remark :查看操作权限
  73 + * @name :viewOperateAuth
  74 + * @author :lyh
  75 + * @method :post
  76 + * @time :2023/7/28 14:56
  77 + */
  78 + public function viewOperateAuth($role_info,$action){
40 $projectMenuModel = new ProjectMenu(); 79 $projectMenuModel = new ProjectMenu();
41 $menu_id = $projectMenuModel->read(['action'=>$action['as']],['id']); 80 $menu_id = $projectMenuModel->read(['action'=>$action['as']],['id']);
42 if($menu_id !== false){ 81 if($menu_id !== false){
@@ -44,7 +83,5 @@ class LoginAuthMiddleware @@ -44,7 +83,5 @@ class LoginAuthMiddleware
44 return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户没有权限']); 83 return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户没有权限']);
45 } 84 }
46 } 85 }
47 - return $next($request);  
48 } 86 }
49 -  
50 } 87 }