From dba07ef64b0910e8aff4ddc5d8d492c5356821c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=99=E5=AD=A6=E6=9D=B0?= Date: Mon, 5 Feb 2018 15:25:53 +0800 Subject: [PATCH] bug fix --- src/PdAuth/Middleware/Authenticate.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/PdAuth/Middleware/Authenticate.php b/src/PdAuth/Middleware/Authenticate.php index 550a13c..469000a 100644 --- a/src/PdAuth/Middleware/Authenticate.php +++ b/src/PdAuth/Middleware/Authenticate.php @@ -63,6 +63,13 @@ class Authenticate //登录状态检测 if ($this->auth->guard($guard)->guest()) { + if ($request->isXmlHttpRequest()) { + return response()->json([ + 'code' => 401, + 'msg' => 'need login', + 'data' => null, + ]); + } return redirect(app('pd.auth')->connect($request->getUri())); } @@ -76,12 +83,19 @@ class Authenticate $match += $privileges[$role]; } } - + if (in_array($path, $match)) { return $next($request); } - abort(403, '无权访问,请联系管理员授权'); + if ($request->isXmlHttpRequest()) { + return response()->json([ + 'code' => 403, + 'msg' => '无权访问,请联系管理员授权', + 'data' => null, + ]); + } + api_abort(403, '无权访问,请联系管理员授权'); return $next($request); } }