コード例 #1
0
ファイル: Api.php プロジェクト: SharkIng/ss-panel
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
 {
     if (Helper::isTesting()) {
         $response = $next($request, $response);
         return $response;
     }
     $accessToken = Helper::getTokenFromReq($request);
     if ($accessToken == null) {
         $res['ret'] = 0;
         $res['msg'] = "token is null";
         $newResponse = $response->withJson($res, 401);
         return $newResponse;
     }
     $storage = Factory::createTokenStorage();
     $token = $storage->get($accessToken);
     if ($token == null) {
         $res['ret'] = 0;
         $res['msg'] = "token is null";
         $newResponse = $response->withJson($res, 401);
         return $newResponse;
     }
     if ($token->expireTime < time()) {
         $res['ret'] = 0;
         $res['msg'] = "token is expire";
         $newResponse = $response->withJson($res, 401);
         return $newResponse;
     }
     $response = $next($request, $response);
     return $response;
 }
コード例 #2
0
ファイル: Api.php プロジェクト: NothingToDoCN/ss-panel
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
 {
     $accessToken = Helper::getTokenFromReq($request);
     if ($accessToken == null) {
         $res['ret'] = 0;
         $res['msg'] = "token is null";
         $response->getBody()->write(json_encode($res));
         return $response;
     }
     $storage = Factory::createTokenStorage();
     $token = $storage->get($accessToken);
     if ($token == null) {
         $res['ret'] = 0;
         $res['msg'] = "token is null";
         $response->getBody()->write(json_encode($res));
         return $response;
     }
     if ($token->expireTime < time()) {
         $res['ret'] = 0;
         $res['msg'] = "token is expire";
         $response->getBody()->write(json_encode($res));
         return $response;
     }
     $response = $next($request, $response);
     return $response;
 }
コード例 #3
0
ファイル: ApiController.php プロジェクト: SharkIng/ss-panel
 public function userInfo($request, $response, $args)
 {
     $id = $args['id'];
     $accessToken = Helper::getTokenFromReq($request);
     $storage = Factory::createTokenStorage();
     $token = $storage->get($accessToken);
     if ($id != $token->userId) {
         $res['ret'] = 0;
         $res['msg'] = "access denied";
         return $this->echoJson($response, $res);
     }
     $user = User::find($token->userId);
     $user->pass = null;
     $data = $user;
     $res['ret'] = 1;
     $res['msg'] = "ok";
     $res['data'] = $data;
     return $this->echoJson($response, $res);
 }
コード例 #4
0
ファイル: Token.php プロジェクト: NothingToDoCN/ss-panel
 public function __construct()
 {
     $this->storage = Factory::createTokenStorage();
 }