Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 public function __construct()
 {
     $this->storage = Factory::createTokenStorage();
 }