/** * __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 deleteSession($apiKey) { UserModel::resetApiKey($apiKey); $this->writeSuccess("Session deleted."); }
/** * @param $userId int */ public function deleteUser($userId) { if ($this->isUserAuthenticated() && $this->currentUser->isAdmin()) { if (UserModel::deleteUser($userId) === true) { $this->writeSuccess("Deleted user " . $userId); } else { $this->writeFail("User not found."); } } else { $this->writeUnauthorized(); } }