From 07a9bbf9ffecd06a99e44edd090c1f2959a1648d 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 21:34:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9,=20=D1=85=D0=BE=D1=82=D1=8C=20=D0=B8=20?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=B1=D1=8B=D0=B9=20=D0=B7=D0=B0=D1=85=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=20JSON'=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthRegistrationExecutor.h | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/endpoints_handlers/AuthRegistrationExecutor.h b/src/endpoints_handlers/AuthRegistrationExecutor.h index 810f146..2ead620 100644 --- a/src/endpoints_handlers/AuthRegistrationExecutor.h +++ b/src/endpoints_handlers/AuthRegistrationExecutor.h @@ -17,7 +17,7 @@ class AuthRegistrationExecutor : public IExecutor public: AuthRegistrationExecutor(mysqlx::Session& session, - std::shared_ptr user_dao) + std::shared_ptr user_dao) : session_(session), user_dao_(user_dao) { } @@ -31,18 +31,35 @@ public: using namespace boost::beast; auto body = req.body(); - object json_as_object = json::parse(body).as_object(); + value req_json; - std::string login = json_as_object.at("login").as_string().c_str(); - std::string password = json_as_object.at("password").as_string().c_str(); + try + { + req_json = json::parse(body); + } + catch (const system::system_error& err) + { + http::response res{http::status::bad_request, req.version()}; + + res.body() = "{ \"detail\": \"cannot deserialize json\"}"; + res.set(http::field::content_type, "application/json"); + res.content_length(res.body().size()); + + return res; + } + + std::string login = req_json.as_object().at("login").as_string().c_str(); + std::string password = req_json.as_object().at("password").as_string().c_str(); + + if (user_dao_->GetByLogin(login).has_value()) + { + } User user; user.SetLogin(login); user.SetPassword(password); - user_dao_->GetByLogin(login); - http::response res{ http::status::ok, req.version() };