CheckUserPermissionMiddleware.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Http\Middleware;
  11. use App\Repositories\Enums\ResponseCodeEnum;
  12. use Closure;
  13. /**
  14. * 检查用户是否有权限
  15. */
  16. class CheckUserPermissionMiddleware
  17. {
  18. /**
  19. * Handle an incoming request.
  20. *
  21. * @param \Illuminate\Http\Request $request
  22. * @param \Closure $next
  23. * @return mixed
  24. */
  25. public function handle($request, Closure $next)
  26. {
  27. $admin = login_admin();
  28. if (!$admin) {
  29. abort(ResponseCodeEnum::HTTP_UNAUTHORIZED, '请先登录');
  30. }
  31. if ($admin->isSuperAdmin()) {
  32. return $next($request);
  33. }
  34. // $method = $request->method();
  35. // $path = str_replace('/', ':', trim($request->path(), '/'));
  36. // $key = "{$method}|{$path}";
  37. // if ($admin->can($key)) {
  38. // return $next($request);
  39. // }
  40. // abort(ResponseCodeEnum::SERVICE_NO_PERMISSION, '没有权限');
  41. return $next($request);
  42. }
  43. }