7 changed files with 84 additions and 10 deletions
@ -0,0 +1,37 @@ |
|||||
|
<?php |
||||
|
declare (strict_types = 1); |
||||
|
|
||||
|
namespace app\middleware; |
||||
|
|
||||
|
use think\Exception; |
||||
|
use think\facade\Request; |
||||
|
use think\facade\Session; |
||||
|
|
||||
|
class CheckAdmin |
||||
|
{ |
||||
|
/** |
||||
|
* 请求处理 |
||||
|
* @param $request |
||||
|
* @param \Closure $next |
||||
|
* @return mixed|\think\response\Json |
||||
|
*/ |
||||
|
public function handle($request, \Closure $next) |
||||
|
{ |
||||
|
try { |
||||
|
$token = Request::header()['token']??false; |
||||
|
if(!$token) |
||||
|
throw new Exception('Without Token',403); |
||||
|
$userinfo = checkToken($token); |
||||
|
if($userinfo['code'] != 200) |
||||
|
throw new Exception('Token checked error',403); |
||||
|
$request->userInfo = $userinfo['data']; |
||||
|
if (!Session::get('login_admin_user_data')) { |
||||
|
throw new Exception('管理员未登陆,请先登陆后操作',201); |
||||
|
} |
||||
|
} |
||||
|
catch (\Exception $err){ |
||||
|
return json(['code'=>$err->getCode(),'msg'=>$err->getMessage()]); |
||||
|
} |
||||
|
return $next($request); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
<?php |
||||
|
declare (strict_types = 1); |
||||
|
|
||||
|
namespace app\middleware; |
||||
|
|
||||
|
use think\Exception; |
||||
|
use think\facade\Request; |
||||
|
use think\facade\Session; |
||||
|
|
||||
|
class CheckAgent |
||||
|
{ |
||||
|
/** |
||||
|
* 处理请求 |
||||
|
* @param $request |
||||
|
* @param \Closure $next |
||||
|
* @return mixed|\think\response\Json |
||||
|
*/ |
||||
|
public function handle($request, \Closure $next) |
||||
|
{ |
||||
|
try { |
||||
|
$token = Request::header()['token']??false; |
||||
|
if(!$token) |
||||
|
throw new Exception('Without Token',403); |
||||
|
$userinfo = checkToken($token); |
||||
|
if($userinfo['code'] != 200) |
||||
|
throw new Exception('Token checked error',403); |
||||
|
$request->userInfo = $userinfo['data']; |
||||
|
if (!Session::get('login_agent_user_data')) { |
||||
|
throw new Exception('代理未登陆,请先登陆后操作',201); |
||||
|
} |
||||
|
} |
||||
|
catch (\Exception $err){ |
||||
|
return json(['code'=>$err->getCode(),'msg'=>$err->getMessage()]); |
||||
|
} |
||||
|
return $next($request); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue