Authenticate.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Base\Middleware;
  3. use Closure;
  4. use Illuminate\Contracts\Auth\Factory as Auth;
  5. use App\Base\Exceptions\ApiException;
  6. class Authenticate
  7. {
  8. /**
  9. * The authentication guard factory instance.
  10. * @var \Illuminate\Contracts\Auth\Factory
  11. */
  12. protected $auth;
  13. /**
  14. * Create a new middleware instance.
  15. * @param \Illuminate\Contracts\Auth\Factory $auth
  16. */
  17. public function __construct(Auth $auth)
  18. {
  19. $this->auth = $auth;
  20. }
  21. /**
  22. * Handle an incoming request.
  23. * @param \Illuminate\Http\Request $request
  24. * @param \Closure $next
  25. * @param string|null $guard
  26. * @return mixed
  27. * @throws ApiException
  28. */
  29. public function handle($request, Closure $next, $guard = null)
  30. {
  31. $user = $request->user();
  32. if (!isset($user['id']) || !$user['id']) {
  33. throw new ApiException('common.auth_fail', '认证失败');
  34. }
  35. if (is_object($user)) {
  36. $user = $user->toArray();
  37. }
  38. // if(!checkApiPermission($user['permissions'],$request->path(), ($request->method() == 'GET' ? $request->all() : []))){
  39. // throw new ApiException('common.no_permission', '没有权限');
  40. // }
  41. return $next($request);
  42. }
  43. }