generated from Sithas/conan_template
Logout переведен на систему исключений вместо возврата
This commit is contained in:
@@ -38,47 +38,29 @@ public:
|
||||
const auto body = req.body();
|
||||
value req_json;
|
||||
|
||||
value response_body;
|
||||
response_body.emplace_object();
|
||||
|
||||
try
|
||||
{
|
||||
req_json = json::parse(body);
|
||||
|
||||
const std::string token = req_json.as_object().at("token").as_string().c_str();
|
||||
|
||||
if (!auth_dao_->Logout(token))
|
||||
{
|
||||
http::response<ResponseType> res{http::status::bad_request, req.version()};
|
||||
|
||||
response_body.as_object().emplace("Result", "token is not authorized");
|
||||
|
||||
res.body() = json::serialize(response_body);
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
http::response<ResponseType> res{http::status::ok, req.version()};
|
||||
|
||||
res.body() = "true"s;
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
return res;
|
||||
}
|
||||
catch (const system::system_error& err)
|
||||
{
|
||||
http::response<ResponseType> res{http::status::bad_request, req.version()};
|
||||
response_body.as_object().emplace("Result", "cannot deserialize json");
|
||||
|
||||
res.body() = serialize(response_body);
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
return res;
|
||||
throw exception400_bad_request("cannot deserialize json"s);
|
||||
}
|
||||
|
||||
const std::string token = req_json.as_object().at("token").as_string().c_str();
|
||||
|
||||
if (!auth_dao_->Logout(token))
|
||||
{
|
||||
throw exception400_bad_request("token is not authorized"s);
|
||||
}
|
||||
|
||||
http::response<ResponseType> res{http::status::ok, req.version()};
|
||||
|
||||
res.body() = "null"s;
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user