/** * __invoke is called by slim when a route matches * @param $request Request * @param $response Response * @param $args array * * * @return $response \Slim\Http\Response */ public function __invoke(Request $request, Response $response, array $args) { $this->response = $response; //check for api key $queryParams = $request->getQueryParams(); if (isset($queryParams['api_key'])) { $userData = UserModel::getUserWithApiKey($queryParams['api_key']); if ($userData !== false) { $this->currentUser = new User($userData); } } $this->response = $this->response->withHeader('Content-type', 'application/json'); }
private function getSession($apiKey) { $user = UserModel::getUserWithApiKey($apiKey); unset($user['password_hash']); //remove password_hash if ($user === false) { $this->writeUnauthorized(); } else { $this->writeSuccess($user); } }