DistAuth.php 879 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use Dcat\Admin\Admin;
  5. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  6. class DistAuth
  7. {
  8. private $excludeList = [
  9. '/auth/users',
  10. '/auth/roles',
  11. '/auth/permissions',
  12. '/auth/menu',
  13. '/auth/extensions',
  14. '/helpers/scaffold',
  15. '/helpers/icons',
  16. ];
  17. public function handle($request, Closure $next)
  18. {
  19. //如果用户非管理员角色,判断是否含以上URL,含有则触发404
  20. foreach ($this->excludeList as $item) {
  21. if (strpos($request->url(), $item) !== false) {
  22. if (!Admin::user()->isAdministrator()) {
  23. throw new NotFoundHttpException; // 触发404
  24. }
  25. }
  26. }
  27. //否则继续处理当前请求
  28. return $next($request);
  29. }
  30. }