работающая авторизация

This commit is contained in:
2024-11-05 10:33:52 +03:00
parent b561dedb2b
commit 0eacd76810
10 changed files with 150 additions and 61 deletions

View File

@@ -134,17 +134,18 @@ public:
rep.headers.clear();
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
try {
std::istringstream is(req.body);
std::istringstream is(std::string(req.payload.data(), req.payload.size()));
boost::property_tree::ptree pt;
boost::property_tree::read_json(is, pt);
read_json(is, pt);
auto u = auth.doAuth(req);
auto u = auth.doAuth(pt.get<std::string>("username"), pt.get<std::string>("password"), rep);
if (u == nullptr) {
throw std::runtime_error("invalid session");
}
std::string result = R"({"redirect":"/"})";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
} catch (std::exception &e) {
BOOST_LOG_TRIVIAL(error) << e.what() << std::endl;
std::string result = R"({"error":"Неверный логин или пароль"})";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
}