From 799890147e96146238f5740912cfbb259802c0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Fri, 29 Aug 2025 18:33:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9?= =?UTF-8?q?=D1=81=D0=B0=20=D0=94=D0=90=D0=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + src/DAO/IUserDAO.h | 2 ++ src/DAO/MySQLUserDAO.cpp | 5 +++++ src/DAO/MySQLUserDAO.h | 2 ++ .../AuthRegistrationExecutor.h | 21 +++++++++++++------ src/entities/User.cpp | 21 ++++++++++++++----- src/entities/User.h | 6 +++++- 7 files changed, 46 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ee71e73..e3b5fa0 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ - Посмотреть пулл соединений(Object pool) при использовании базы данных(посмотреть api MySQL-Connector) - Посмотреть, что дает MySQL, какие там есть возможность - Посмотреть и подумать, что лучше - корутины или многопоточность? +- Покрыть тестами класс User и AuthRegistrationExecutor # UseCase'ы приложения: diff --git a/src/DAO/IUserDAO.h b/src/DAO/IUserDAO.h index d68c3fc..1b4c805 100644 --- a/src/DAO/IUserDAO.h +++ b/src/DAO/IUserDAO.h @@ -14,6 +14,8 @@ public: virtual std::optional GetByGUID(std::string guid) = 0; + virtual std::optional GetByLogin(std::string login) = 0; + virtual std::vector GetAll() = 0; virtual bool Update(const User& u) = 0; diff --git a/src/DAO/MySQLUserDAO.cpp b/src/DAO/MySQLUserDAO.cpp index ed5f1f5..2b3d29e 100644 --- a/src/DAO/MySQLUserDAO.cpp +++ b/src/DAO/MySQLUserDAO.cpp @@ -21,6 +21,11 @@ optional MySQLUserDAO::GetByGUID(string guid) return nullopt; } +std::optional MySQLUserDAO::GetByLogin(std::string login) +{ + return nullopt; +} + vector MySQLUserDAO::GetAll() { vector users {}; diff --git a/src/DAO/MySQLUserDAO.h b/src/DAO/MySQLUserDAO.h index 832007a..106470c 100644 --- a/src/DAO/MySQLUserDAO.h +++ b/src/DAO/MySQLUserDAO.h @@ -14,6 +14,8 @@ public: std::optional GetByGUID(std::string guid); + std::optional GetByLogin(std::string login); + std::vector GetAll(); bool Update(const User& u); diff --git a/src/endpoints_handlers/AuthRegistrationExecutor.h b/src/endpoints_handlers/AuthRegistrationExecutor.h index 9a020f8..6fe9c77 100644 --- a/src/endpoints_handlers/AuthRegistrationExecutor.h +++ b/src/endpoints_handlers/AuthRegistrationExecutor.h @@ -26,18 +26,27 @@ public: boost::beast::http::request>&& req ) override { + using namespace boost; + using namespace boost::json; + using namespace boost::beast; + auto body = req.body(); - boost::json::object json_as_object = boost::json::parse(body).as_object(); + object json_as_object = json::parse(body).as_object(); - std::string login = boost::json::serialize(json_as_object.at("login").as_string()); - std::string password = boost::json::serialize(json_as_object.at("password").as_string()); + std::string login = serialize(json_as_object.at("login").as_string()); + std::string password = serialize(json_as_object.at("password").as_string()); - boost::beast::http::response res{ - boost::beast::http::status::ok, req.version() + User user; + + user.SetLogin(login); + user.SetPassword(password); + + http::response res{ + http::status::ok, req.version() }; res.body() = "{ \"detail\": \"ok\"}"; - res.set(boost::beast::http::field::content_type, "application/json"); + res.set(http::field::content_type, "application/json"); res.content_length(res.body().size()); return res; diff --git a/src/entities/User.cpp b/src/entities/User.cpp index 3b31834..8bd8457 100644 --- a/src/entities/User.cpp +++ b/src/entities/User.cpp @@ -1,28 +1,39 @@ +#include +#include + #include "User.h" +using namespace std; + namespace uad { -const std::string& User::GetGUID() const noexcept +const string& User::GetGUID() const noexcept { return guid_; } -void User::SetGUID(const std::string& new_guid) +void User::SetGUID(const string& new_guid) { guid_ = new_guid; } -const std::string& User::GetLogin() const noexcept +const string& User::GetLogin() const noexcept { return login_; } -void User::SetLogin(const std::string& login) +void User::SetLogin(const string& login) { login_ = login; } -const std::string& User::GetHashedPassword() const noexcept +void User::SetPassword(const string& password) +{ + size_t calculated_hash = hash{}(password); + hashed_password_ = ToHex((byte*)&calculated_hash, sizeof(calculated_hash)); +} + +const string& User::GetHashedPassword() const noexcept { return hashed_password_; } diff --git a/src/entities/User.h b/src/entities/User.h index bfdcaa2..424aae3 100644 --- a/src/entities/User.h +++ b/src/entities/User.h @@ -2,13 +2,15 @@ #include +#include "../helpers/helpers.h" + namespace uad { class User { std::string guid_; std::string login_; - const std::string hashed_password_; + std::string hashed_password_; public: [[nodiscard]] const std::string& GetGUID() const noexcept; @@ -18,6 +20,8 @@ public: void SetLogin(const std::string& login); + void SetPassword(const std::string& password); + [[nodiscard]] const std::string& GetHashedPassword() const noexcept; }; }