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
* @return mixed
*/
public function handle($request, Closure $next, $guard = 'auth')
public function handle($request, Closure $next, $guard = null)
{
//oauth 回调
$code = $request->input('pd_code');
@ -55,22 +55,29 @@ class Authenticate
}
$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()) {
$redirect = $request->input('redirect', $request->getUri());
if ($request->isXmlHttpRequest()) {
return response()->json([
'code' => 401,
'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()));
}
//权限检测

View File

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