作者 lyh

gx

... ... @@ -6,6 +6,7 @@ use App\Enums\Common\Code;
use App\Http\Logic\Aside\LoginLogic;
use App\Models\Manage\Group;
use App\Models\Manage\Manage;
use App\Models\Manage\Menu;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
... ... @@ -32,7 +33,44 @@ class LoginAuthMiddleware
return response(['code'=> Code::USER_LOGIN_ERROE,'msg'=>'当前用户被禁用']);
}
}
//TODO::查看当前角色是否被禁用
$groupInfo = $this->getGroup($manage);
//获取当前操作的路由name
$action = Route::currentRouteName();
//TODO::操作权限
$this->viewOperateAuth($groupInfo,$action);
return $next($request);
}
/**
* @remark :查看角色是否被禁用
* @name :getGroup
* @author :lyh
* @method :post
* @time :2023/7/28 15:26
*/
public function getGroup($manage){
$groupModel = new Group();
$groupInfo = $groupModel->read(['id'=>$manage['gid']]);
if($groupInfo['status'] != 0){
return response(['code'=> Code::USER_LOGIN_ERROE,'msg'=>'当前用户角色被禁用']);
}
return $groupInfo;
}
/**
* @remark :查看操作权限
* @name :viewOperateAuth
* @author :lyh
* @method :post
* @time :2023/7/28 14:56
*/
public function viewOperateAuth($groupInfo,$action){
$menuModel = new Menu();
$menu_id = $menuModel->read(['route_name'=>$action],['id']);
if($menu_id !== false){
if(strpos($groupInfo['rights'], $menu_id['id']) < 0){
return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户没有权限']);
}
}
}
}
... ...
... ... @@ -28,7 +28,7 @@ class LoginAuthMiddleware
return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户未登录']);
}
$role_info = $this->setRole($info);
//获取当前操作的控制器与方法
//获取当前操作的路由name
$action = Route::currentRouteName();
//查询当前用户是否拥有权限操作
$this->viewOperateAuth($role_info,$action);
... ...