generated from Sithas/conan_template
Почти завершенная регистрация
This commit is contained in:
@@ -30,9 +30,13 @@ public:
|
|||||||
using namespace boost;
|
using namespace boost;
|
||||||
using namespace boost::json;
|
using namespace boost::json;
|
||||||
using namespace boost::beast;
|
using namespace boost::beast;
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
auto body = req.body();
|
auto body = req.body();
|
||||||
value req_json;
|
value req_json;
|
||||||
|
value response_body;
|
||||||
|
|
||||||
|
response_body.emplace_object();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -41,8 +45,9 @@ public:
|
|||||||
catch (const system::system_error& err)
|
catch (const system::system_error& err)
|
||||||
{
|
{
|
||||||
http::response<ResponseType> res{http::status::bad_request, req.version()};
|
http::response<ResponseType> res{http::status::bad_request, req.version()};
|
||||||
|
response_body.as_object().emplace("Result", "cannot deserialize json");
|
||||||
|
|
||||||
res.body() = "{ \"Result\": \"cannot deserialize json\"}";
|
res.body() = serialize(response_body);
|
||||||
res.set(http::field::content_type, "application/json");
|
res.set(http::field::content_type, "application/json");
|
||||||
res.content_length(res.body().size());
|
res.content_length(res.body().size());
|
||||||
|
|
||||||
@@ -56,7 +61,12 @@ public:
|
|||||||
{
|
{
|
||||||
http::response<ResponseType> res{http::status::unprocessable_entity, req.version()};
|
http::response<ResponseType> res{http::status::unprocessable_entity, req.version()};
|
||||||
|
|
||||||
res.body() = "{ \"Result\": \"validations failed\"}";
|
response_body.as_object().emplace(
|
||||||
|
"Result",
|
||||||
|
"Validations failed. Login should have length from 3 to 50. Password from 5 characters length."
|
||||||
|
);
|
||||||
|
|
||||||
|
res.body() = serialize(response_body);
|
||||||
res.set(http::field::content_type, "application/json");
|
res.set(http::field::content_type, "application/json");
|
||||||
res.content_length(res.body().size());
|
res.content_length(res.body().size());
|
||||||
|
|
||||||
@@ -67,7 +77,12 @@ public:
|
|||||||
{
|
{
|
||||||
http::response<ResponseType> res{http::status::conflict, req.version()};
|
http::response<ResponseType> res{http::status::conflict, req.version()};
|
||||||
|
|
||||||
res.body() = "{ \"Result\": \"user with login " + login + " exists\" }";
|
response_body.as_object().emplace(
|
||||||
|
"Result",
|
||||||
|
"user with login "s + login + " exists"s
|
||||||
|
);
|
||||||
|
|
||||||
|
res.body() = serialize(response_body);
|
||||||
res.set(http::field::content_type, "application/json");
|
res.set(http::field::content_type, "application/json");
|
||||||
res.content_length(res.body().size());
|
res.content_length(res.body().size());
|
||||||
|
|
||||||
@@ -83,7 +98,12 @@ public:
|
|||||||
http::status::created, req.version()
|
http::status::created, req.version()
|
||||||
};
|
};
|
||||||
|
|
||||||
res.body() = "{ \"Result\": \"ok\"}";
|
response_body.as_object().emplace(
|
||||||
|
"Result",
|
||||||
|
"OK.Created."
|
||||||
|
);
|
||||||
|
|
||||||
|
res.body() = serialize(response_body);
|
||||||
res.set(http::field::content_type, "application/json");
|
res.set(http::field::content_type, "application/json");
|
||||||
res.content_length(res.body().size());
|
res.content_length(res.body().size());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user