add xml request

This commit is contained in:
候学杰 2018-05-02 16:37:30 +08:00
parent ebaae507a4
commit 24f08057f8
2 changed files with 16 additions and 8 deletions

View File

@ -37,7 +37,7 @@ class Authenticate
* @param string|null $guard * @param string|null $guard
* @return mixed * @return mixed
*/ */
public function handle($request, Closure $next, $guard = 'auth') public function handle($request, Closure $next, $guard = null)
{ {
//oauth 回调 //oauth 回调
$code = $request->input('pd_code'); $code = $request->input('pd_code');
@ -55,22 +55,29 @@ class Authenticate
} }
$qs .= $v . '&'; $qs .= $v . '&';
} }
abort(302, '', [
'Location' => $request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo() . $qs, if (!$request->isXmlHttpRequest()) {
]); abort(302, '', [
'Location' => $request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo() . $qs,
]);
}
} }
} }
//登录状态检测 //登录状态检测
if ($this->auth->guard($guard)->guest()) { if ($this->auth->guard($guard)->guest()) {
$redirect = $request->input('redirect', $request->getUri());
if ($request->isXmlHttpRequest()) { if ($request->isXmlHttpRequest()) {
return response()->json([ return response()->json([
'code' => 401, 'code' => 401,
'msg' => 'need login', 'msg' => 'need login',
'data' => null, 'data' => [
'url' => app('pd.auth')->connect($redirect),
],
]); ]);
} else {
return redirect(app('pd.auth')->connect($redirect));
} }
return redirect(app('pd.auth')->connect($request->getUri()));
} }
//权限检测 //权限检测
@ -103,7 +110,7 @@ class Authenticate
// ]); // ]);
// } // }
// api_abort(403, '无权访问,请联系管理员授权'); // api_abort(403, '无权访问,请联系管理员授权');
return $next($request); return $next($request);
} }
} }

View File

@ -38,12 +38,13 @@ class PdAuthServiceProvider extends ServiceProvider
} }
return null; return null;
}); });
// //
$config = $this->app['config']['auth']; $config = $this->app['config']['auth'];
if (!isset($config['guards']['auth'])) { if (!isset($config['guards']['auth'])) {
config(['auth.guards.auth' => ['driver' => 'auth']]); config(['auth.guards.auth' => ['driver' => 'auth']]);
config(['auth.defaults.guard' => 'auth']); $this->app['auth']->shouldUse('auth');
} }
} }