generated from Sithas/conan_template
Logout переведен на систему исключений вместо возврата
This commit is contained in:
@@ -141,7 +141,7 @@ null
|
|||||||
```
|
```
|
||||||
|
|
||||||
##### Errors
|
##### Errors
|
||||||
* `401 BAD_CREDENTIALS` — Такого токена не существует(B3)
|
* `400 BAD_REQUEST` — Такого токена не существует(B3)
|
||||||
|
|
||||||
### 10. Используемые сущности ДБ
|
### 10. Используемые сущности ДБ
|
||||||
* users(uuid(PK), login(unique), hashed_password)
|
* users(uuid(PK), login(unique), hashed_password)
|
||||||
|
|||||||
@@ -38,47 +38,29 @@ public:
|
|||||||
const auto body = req.body();
|
const auto body = req.body();
|
||||||
value req_json;
|
value req_json;
|
||||||
|
|
||||||
value response_body;
|
|
||||||
response_body.emplace_object();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
req_json = json::parse(body);
|
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)
|
catch (const system::system_error& err)
|
||||||
{
|
{
|
||||||
http::response<ResponseType> res{http::status::bad_request, req.version()};
|
throw exception400_bad_request("cannot deserialize json"s);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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