generated from Sithas/conan_template
Доработка интерфейса ДАО
This commit is contained in:
@@ -14,6 +14,8 @@ public:
|
||||
|
||||
virtual std::optional<User> GetByGUID(std::string guid) = 0;
|
||||
|
||||
virtual std::optional<User> GetByLogin(std::string login) = 0;
|
||||
|
||||
virtual std::vector<User> GetAll() = 0;
|
||||
|
||||
virtual bool Update(const User& u) = 0;
|
||||
|
||||
@@ -21,6 +21,11 @@ optional<User> MySQLUserDAO::GetByGUID(string guid)
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
std::optional<User> MySQLUserDAO::GetByLogin(std::string login)
|
||||
{
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
vector<User> MySQLUserDAO::GetAll()
|
||||
{
|
||||
vector<User> users {};
|
||||
|
||||
@@ -14,6 +14,8 @@ public:
|
||||
|
||||
std::optional<User> GetByGUID(std::string guid);
|
||||
|
||||
std::optional<User> GetByLogin(std::string login);
|
||||
|
||||
std::vector<User> GetAll();
|
||||
|
||||
bool Update(const User& u);
|
||||
|
||||
@@ -26,18 +26,27 @@ public:
|
||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||
) override
|
||||
{
|
||||
using namespace boost;
|
||||
using namespace boost::json;
|
||||
using namespace boost::beast;
|
||||
|
||||
auto body = req.body();
|
||||
boost::json::object json_as_object = boost::json::parse(body).as_object();
|
||||
object json_as_object = json::parse(body).as_object();
|
||||
|
||||
std::string login = boost::json::serialize(json_as_object.at("login").as_string());
|
||||
std::string password = boost::json::serialize(json_as_object.at("password").as_string());
|
||||
std::string login = serialize(json_as_object.at("login").as_string());
|
||||
std::string password = serialize(json_as_object.at("password").as_string());
|
||||
|
||||
boost::beast::http::response<ResponseType> res{
|
||||
boost::beast::http::status::ok, req.version()
|
||||
User user;
|
||||
|
||||
user.SetLogin(login);
|
||||
user.SetPassword(password);
|
||||
|
||||
http::response<ResponseType> res{
|
||||
http::status::ok, req.version()
|
||||
};
|
||||
|
||||
res.body() = "{ \"detail\": \"ok\"}";
|
||||
res.set(boost::beast::http::field::content_type, "application/json");
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
return res;
|
||||
|
||||
+16
-5
@@ -1,28 +1,39 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "User.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace uad
|
||||
{
|
||||
const std::string& User::GetGUID() const noexcept
|
||||
const string& User::GetGUID() const noexcept
|
||||
{
|
||||
return guid_;
|
||||
}
|
||||
|
||||
void User::SetGUID(const std::string& new_guid)
|
||||
void User::SetGUID(const string& new_guid)
|
||||
{
|
||||
guid_ = new_guid;
|
||||
}
|
||||
|
||||
const std::string& User::GetLogin() const noexcept
|
||||
const string& User::GetLogin() const noexcept
|
||||
{
|
||||
return login_;
|
||||
}
|
||||
|
||||
void User::SetLogin(const std::string& login)
|
||||
void User::SetLogin(const string& login)
|
||||
{
|
||||
login_ = login;
|
||||
}
|
||||
|
||||
const std::string& User::GetHashedPassword() const noexcept
|
||||
void User::SetPassword(const string& password)
|
||||
{
|
||||
size_t calculated_hash = hash<string>{}(password);
|
||||
hashed_password_ = ToHex((byte*)&calculated_hash, sizeof(calculated_hash));
|
||||
}
|
||||
|
||||
const string& User::GetHashedPassword() const noexcept
|
||||
{
|
||||
return hashed_password_;
|
||||
}
|
||||
|
||||
+5
-1
@@ -2,13 +2,15 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../helpers/helpers.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class User
|
||||
{
|
||||
std::string guid_;
|
||||
std::string login_;
|
||||
const std::string hashed_password_;
|
||||
std::string hashed_password_;
|
||||
public:
|
||||
[[nodiscard]] const std::string& GetGUID() const noexcept;
|
||||
|
||||
@@ -18,6 +20,8 @@ public:
|
||||
|
||||
void SetLogin(const std::string& login);
|
||||
|
||||
void SetPassword(const std::string& password);
|
||||
|
||||
[[nodiscard]] const std::string& GetHashedPassword() const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user