Ejemplo 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;
 }
Ejemplo 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;
 }
Ejemplo n.º 3
0
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
 {
     if (Helper::isTesting()) {
         $response = $next($request, $response);
         return $response;
     }
     $user = AuthService::getUser();
     if (!$user->isLogin) {
         $newResponse = $response->withStatus(302)->withHeader('Location', '/auth/login');
         return $newResponse;
     }
     $response = $next($request, $response);
     return $response;
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
 {
     $key = Helper::getMuKeyFromReq($request);
     if ($key == null) {
         $res['ret'] = 0;
         $res['msg'] = "key is null";
         $newResponse = $response->withStatus(401);
         $newResponse->getBody()->write(json_encode($res));
         return $newResponse;
     }
     if ($key != Config::get('muKey')) {
         $res['ret'] = 0;
         $res['msg'] = "token is  invalid";
         $newResponse = $response->withStatus(401);
         $newResponse->getBody()->write(json_encode($res));
         return $newResponse;
     }
     $response = $next($request, $response);
     return $response;
 }
Ejemplo n.º 6
0
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
 {
     if (Helper::isTesting()) {
         $response = $next($request, $response);
         return $response;
     }
     $key = Helper::getMuKeyFromReq($request);
     if ($key == null) {
         $res['ret'] = 0;
         $res['msg'] = "key is null";
         $newResponse = $response->withJson($res, 401);
         return $newResponse;
     }
     if ($key != Config::get('muKey')) {
         $res['ret'] = 0;
         $res['msg'] = "token is  invalid";
         $newResponse = $response->withJson($res, 401);
         return $newResponse;
     }
     $response = $next($request, $response);
     return $response;
 }
Ejemplo n.º 7
0
 /**
  * @return User|void
  */
 public static function getUser()
 {
     if (Helper::isTesting()) {
         $user = User::first();
         $user->isLogin = true;
         return $user;
     }
     $sid = Cookie::get('sid');
     $value = self::getCache()->get($sid);
     if ($value == null || !$value) {
         $user = new User();
         $user->isLogin = false;
         return $user;
     }
     $uid = $value;
     $user = User::find($uid);
     if ($user == null) {
         $user = new User();
         $user->isLogin = false;
         return $user;
     }
     $user->isLogin = true;
     return $user;
 }