ManageAuth.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\common\middleware;
  3. //验证权限
  4. class ManageAuth
  5. {
  6. public function handle($request, \Closure $next)
  7. {
  8. // 设置演示模式,演示模式下无法修改配置
  9. $request->demonMode=env('app.demon_mode',false);
  10. if(!$request->demonMode){
  11. if($request->userInfo['user_id']!=1 && $request->userInfo['role']!=2){
  12. shutdown('您没有权限访问该接口',-1);
  13. }
  14. }else{
  15. $rules=[
  16. 'user/add',
  17. 'user/edit',
  18. 'user/del',
  19. 'user/setrole',
  20. 'user/setstatus',
  21. 'user/editpassword',
  22. 'group/del',
  23. 'group/changeowner',
  24. 'group/delgroupuser',
  25. 'task/starttask',
  26. 'task/stoptask',
  27. 'config/setconfig'
  28. ];
  29. // 获取pathinfo信息
  30. $pathinfo = strtolower($request->pathinfo());
  31. if(in_array($pathinfo,$rules)){
  32. return shutdown('演示模式下无法操作!',400);
  33. }
  34. }
  35. return $next($request);
  36. }
  37. }