From 598bcba4a906690369307c8d894b1e9e4673aeb5 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Wed, 14 Aug 2024 00:59:19 +0200 Subject: [PATCH] Change unicode and introduce new model user --- SpCloudMain/CMakeLists.txt | 2 +- SpCloudMain/Controllers/PublishController.cpp | 3 +- SpCloudMain/Models/User.cpp | 50 +++++++++++++++++++ SpCloudMain/Service/AuthorizationService.cpp | 8 ++- SpCloudMain/Service/FileProcessingService.cpp | 27 +--------- 5 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 SpCloudMain/Models/User.cpp diff --git a/SpCloudMain/CMakeLists.txt b/SpCloudMain/CMakeLists.txt index 58b9773..df17ade 100644 --- a/SpCloudMain/CMakeLists.txt +++ b/SpCloudMain/CMakeLists.txt @@ -11,7 +11,7 @@ add_executable(SpCloudMain "Service/FileProcessingService.cpp" "Service/CommandService.cpp" "Service/Logger.cpp" -) + "Models/User.cpp") if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET SpCloudMain PROPERTY CXX_STANDARD 20) diff --git a/SpCloudMain/Controllers/PublishController.cpp b/SpCloudMain/Controllers/PublishController.cpp index 9f223e0..d098078 100644 --- a/SpCloudMain/Controllers/PublishController.cpp +++ b/SpCloudMain/Controllers/PublishController.cpp @@ -31,7 +31,8 @@ public: public: void process_publish(const httplib::Request& req, httplib::Response& res) { - if (this->authorization.is_user_authorized()) + //if (this->authorization.is_user_authorized()) + if (true)//Todo change to is user authorized { const auto& content = req.files.begin()->second.content; diff --git a/SpCloudMain/Models/User.cpp b/SpCloudMain/Models/User.cpp new file mode 100644 index 0000000..75c2095 --- /dev/null +++ b/SpCloudMain/Models/User.cpp @@ -0,0 +1,50 @@ +#include + +class User { +private: + int id; + std::string name; + std::string authToken; + bool isBanned; + +public: + // Конструктор + User(int id, const std::string& name, const std::string& authToken, bool isBanned) + : id(id), name(name), authToken(authToken), isBanned(isBanned) {} + + // Геттеры и сеттеры для Id + int getId() const { + return id; + } + + void setId(int id) { + this->id = id; + } + + // Геттеры и сеттеры для Name + std::string getName() const { + return name; + } + + void setName(const std::string& name) { + this->name = name; + } + + // Геттеры и сеттеры для AuthToken + std::string getAuthToken() const { + return authToken; + } + + void setAuthToken(const std::string& authToken) { + this->authToken = authToken; + } + + // Геттеры и сеттеры для IsBanned + bool getIsBanned() const { + return isBanned; + } + + void setIsBanned(bool isBanned) { + this->isBanned = isBanned; + } +}; diff --git a/SpCloudMain/Service/AuthorizationService.cpp b/SpCloudMain/Service/AuthorizationService.cpp index 374f1c4..b79edbd 100644 --- a/SpCloudMain/Service/AuthorizationService.cpp +++ b/SpCloudMain/Service/AuthorizationService.cpp @@ -1,10 +1,14 @@ +#include "../Models/User.cpp" + + class AuthorizationService { public: - bool is_user_authorized() + bool is_user_authorized(User user) { return true;//Todo implement logic for authorization processing } -}; + +}; diff --git a/SpCloudMain/Service/FileProcessingService.cpp b/SpCloudMain/Service/FileProcessingService.cpp index 678ae06..86b8e54 100644 --- a/SpCloudMain/Service/FileProcessingService.cpp +++ b/SpCloudMain/Service/FileProcessingService.cpp @@ -9,6 +9,7 @@ #include "Logger.cpp" class FileProcessingService { + Logger& logger_; public: FileProcessingService(Logger& logger) : logger_(logger) @@ -42,14 +43,6 @@ public: void unzip(const std::string& file_path, const std::string& final_files_directory) { create_directory(final_files_directory); - //Windows version - //std::string command = R"(powershell -Command "& \"C:\Program Files\WinRAR\WinRAR.exe\" x \")" + file_path + R"(\" \")" + final_files_directory + R"(\")"; - - //Linux version - //std::string command = "unzip " + file_path + " -d " + final_files_directory; - - - std::string command = "unrar x " + file_path + " " + final_files_directory; logger_.log(INFO, "Start unzip command" + command); @@ -68,25 +61,7 @@ public: return ""; //todo add throwing exception } - //static void execute_command(const std::string& command) {//todo delete if not needed - // int result = std::system(command.c_str()); // NOLINT(concurrency-mt-unsafe) - // if (result != 0) { - // std::cerr << "Command failed with code: " << result << std::endl; - // } - //} - - //void unzip(const std::string& file_path, const std::string& final_files_directory) - //{ - // std::string createDirCommand = "mkdir \"" + final_files_directory + "\""; - - // system(createDirCommand.c_str());//Todo solve unsafe warning - - // const std::string command = "WinRAR x \"" + file_path + "\" \"" + final_files_directory + "\""; - - // int result = system(command.c_str());//Todo solve unsafe warning - //} /*private: std::mutex file_mutex; */// Мьютекс для синхронизации доступа к файлу - Logger& logger_; };