generated from Sithas/conan_template
Рабочая сборка второго executor'а
This commit is contained in:
@@ -114,7 +114,6 @@
|
|||||||
```
|
```
|
||||||
{
|
{
|
||||||
"token": af32df3bas739f272bd109c823
|
"token": af32df3bas739f272bd109c823
|
||||||
"expiresIn": 36000000 // 10 часов
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,25 @@ public:
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
req_json = json::parse(body);
|
req_json = json::parse(body);
|
||||||
|
|
||||||
|
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 (login.empty() || password.empty())
|
||||||
|
{
|
||||||
|
http::response<ResponseType> res{http::status::unprocessable_entity, req.version()};
|
||||||
|
response_body.as_object().emplace("Result", "Login or password are empty");
|
||||||
|
|
||||||
|
res.body() = serialize(response_body);
|
||||||
|
res.set(http::field::content_type, "application/json");
|
||||||
|
res.content_length(res.body().size());
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string hashed_password = HashPassword(password);
|
||||||
|
|
||||||
|
std::optional<User> maybe_user = user_dao_->GetByLogin(login);
|
||||||
}
|
}
|
||||||
catch (const system::system_error& err)
|
catch (const system::system_error& err)
|
||||||
{
|
{
|
||||||
@@ -57,67 +76,6 @@ public:
|
|||||||
|
|
||||||
return res;
|
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 (!ValidateLogin(login) || !ValidatePassword(password))
|
|
||||||
{
|
|
||||||
http::response<ResponseType> res{http::status::unprocessable_entity, req.version()};
|
|
||||||
|
|
||||||
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.content_length(res.body().size());
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user_dao_->GetByLogin(login).has_value())
|
|
||||||
{
|
|
||||||
http::response<ResponseType> res{http::status::conflict, req.version()};
|
|
||||||
|
|
||||||
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.content_length(res.body().size());
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
User user;
|
|
||||||
|
|
||||||
user.SetLogin(login);
|
|
||||||
user.SetPassword(password);
|
|
||||||
|
|
||||||
const auto uuid_stringified = user_dao_->Create(user);
|
|
||||||
|
|
||||||
http::response<ResponseType> res{
|
|
||||||
http::status::created, req.version()
|
|
||||||
};
|
|
||||||
|
|
||||||
response_body.as_object().emplace(
|
|
||||||
"uuid",
|
|
||||||
uuid_stringified
|
|
||||||
);
|
|
||||||
response_body.as_object().emplace(
|
|
||||||
"login",
|
|
||||||
user.GetLogin()
|
|
||||||
);
|
|
||||||
|
|
||||||
res.body() = serialize(response_body);
|
|
||||||
res.set(http::field::content_type, "application/json");
|
|
||||||
res.content_length(res.body().size());
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -116,6 +116,12 @@ std::string ToHex(std::byte* src, size_t len)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string HashPassword(const std::string& password)
|
||||||
|
{
|
||||||
|
size_t calculated_hash = std::hash<string>{}(password);
|
||||||
|
return ToHex((byte*)&calculated_hash, sizeof(calculated_hash));
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t Random()
|
uint64_t Random()
|
||||||
{
|
{
|
||||||
std::random_device device;
|
std::random_device device;
|
||||||
|
|||||||
@@ -12,5 +12,7 @@ void Fail(boost::beast::error_code ec, char const* what);
|
|||||||
|
|
||||||
std::string ToHex(std::byte* src, size_t len);
|
std::string ToHex(std::byte* src, size_t len);
|
||||||
|
|
||||||
|
std::string HashPassword(const std::string& password);
|
||||||
|
|
||||||
uint64_t Random();
|
uint64_t Random();
|
||||||
} // namespace uad
|
} // namespace uad
|
||||||
|
|||||||
Reference in New Issue
Block a user