void WebUserManager::removeSession(const SessionPtr& aSession) noexcept { aSession->getUser()->removeSession(); fire(WebUserManagerListener::UserUpdated(), aSession->getUser()); { WLock l(cs); sessionsRemoteId.erase(aSession->getAuthToken()); sessionsLocalId.erase(aSession->getId()); } }
json SessionApi::serializeSession(const SessionPtr& aSession) noexcept { return{ { "id", aSession->getId() }, { "secure", aSession->isSecure() }, { "last_activity", aSession->getLastActivity() }, { "ip", aSession->getIp() }, { "user", { { "id", aSession->getUser()->getToken() }, { "username", aSession->getUser()->getUserName() }, } } }; }
websocketpp::http::status_code::value FileServer::handlePostRequest(const websocketpp::http::parser::request& aRequest, std::string& output_, StringPairList& headers_, const SessionPtr& aSession) noexcept { const auto& requestPath = aRequest.get_uri(); if (requestPath == "/temp") { if (!aSession || !aSession->getUser()->hasPermission(Access::FILESYSTEM_EDIT)) { output_ = "Not authorized"; return websocketpp::http::status_code::unauthorized; } const auto fileName = Util::toString(Util::rand()); const auto filePath = Util::getTempPath() + fileName; try { File file(filePath, File::WRITE, File::TRUNCATE | File::CREATE, File::BUFFER_SEQUENTIAL); file.write(aRequest.get_body()); } catch (const FileException& e) { output_ = "Failed to write the file: " + e.getError(); return websocketpp::http::status_code::internal_server_error; } { WLock l(cs); tempFiles.emplace(fileName, filePath); } headers_.emplace_back("Location", fileName); return websocketpp::http::status_code::created; } output_ = "Requested resource was not found"; return websocketpp::http::status_code::not_found; }