AuthenticateAdmin.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Models\UserInfoModel;
  4. use Closure,Auth;
  5. class AuthenticateAdmin
  6. {
  7. /**
  8. * Handle an incoming request.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @param \Closure $next
  12. * @param string|null $guard
  13. * @return mixed
  14. */
  15. public function handle($request, Closure $next)
  16. {
  17. if(Auth::guard('admin')->guest()){
  18. exit("你没有登录<a target='_parent' href='/admin/logout?returnUrl=" . urlencode('http://'.$_SERVER['HTTP_HOST']) . "'>请登录</a>");
  19. }
  20. $path = $request->path();
  21. if ($path == 'admin') {
  22. $path = str_replace('admin' ,'/', $path);
  23. }else{
  24. $path = str_replace('admin/' ,'', $path);
  25. }
  26. $role = session(LOGIN_MARK_SESSION_KEY);
  27. $user =Auth::guard('admin')->user();
  28. // if(!$user['is_root']) {
  29. // if(!isset($role['role']) || !$role['role']) {
  30. // exit("你没有操作权限1<a target='_parent' href='/admin/logout?returnUrl=" . urlencode('http://'.$_SERVER['HTTP_HOST']) . "'>重新登录</a>");
  31. // }
  32. // /* if(!array_key_exists($path,$role['role'])) {
  33. // exit("你没有操作权限2<a target='_parent' href='/admin/logout?returnUrl=" . urlencode('http://'.$_SERVER['HTTP_HOST']) . "'>重新登录</a>");
  34. // }*/
  35. // }
  36. return $next($request);
  37. }
  38. }