generated from Sithas/conan_template
Рабочая сборка второго executor'а
This commit is contained in:
+3
-1
@@ -10,7 +10,9 @@ namespace uad
|
||||
class IAuthDAO
|
||||
{
|
||||
public:
|
||||
virtual std::string Login(const std::string& registrated_user_uuid) = 0;
|
||||
virtual std::string Login(
|
||||
const std::string& registrated_user_uuid,
|
||||
const std::string& auth_token) = 0;
|
||||
|
||||
virtual bool HasAuthorized(const std::string& auth_token) = 0;
|
||||
|
||||
|
||||
@@ -10,12 +10,10 @@ MemoryAuthDAO::MemoryAuthDAO(mysqlx::Session& session): session_(session)
|
||||
{
|
||||
}
|
||||
|
||||
std::string MemoryAuthDAO::Login(const std::string& registrated_user_uuid)
|
||||
std::string MemoryAuthDAO::Login(
|
||||
const std::string& registrated_user_uuid,
|
||||
const std::string& auth_token)
|
||||
{
|
||||
boost::uuids::random_generator generator;
|
||||
boost::uuids::uuid uuid = generator();
|
||||
std::string auth_token = boost::uuids::to_string(uuid);
|
||||
|
||||
users_uuids_to_auth_tokens_[registrated_user_uuid] = auth_token;
|
||||
auth_tokens_to_users_uuids_[auth_token] = registrated_user_uuid;
|
||||
|
||||
|
||||
@@ -19,7 +19,9 @@ class MemoryAuthDAO : public uad::IAuthDAO
|
||||
public:
|
||||
explicit MemoryAuthDAO(mysqlx::Session& session);
|
||||
|
||||
std::string Login(const std::string& registrated_user_uuid) override;
|
||||
std::string Login(
|
||||
const std::string& registrated_user_uuid,
|
||||
const std::string& auth_token) override;
|
||||
|
||||
bool HasAuthorized(const std::string& auth_token) override;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "IExecutor.h"
|
||||
#include "../DAO/IUserDAO.h"
|
||||
#include "../DAO/IAuthDAO.h"
|
||||
#include "../helpers/helpers.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
@@ -74,6 +75,17 @@ public:
|
||||
|
||||
return res;
|
||||
}
|
||||
auto token = GenerateUUID();
|
||||
auth_dao_->Login(user.value().GetUUID(), token);
|
||||
|
||||
http::response<ResponseType> res{http::status::ok, req.version()};
|
||||
response_body.as_object().emplace("token", token);
|
||||
|
||||
res.body() = serialize(response_body);
|
||||
res.set(http::field::content_type, "application/json");
|
||||
res.content_length(res.body().size());
|
||||
|
||||
return res;
|
||||
}
|
||||
catch (const system::system_error& err)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <random>
|
||||
#include <boost/uuid.hpp>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/format.hpp>
|
||||
@@ -122,6 +123,13 @@ std::string HashPassword(const std::string& password)
|
||||
return ToHex((byte*)&calculated_hash, sizeof(calculated_hash));
|
||||
}
|
||||
|
||||
std::string GenerateUUID()
|
||||
{
|
||||
uuids::random_generator generator;
|
||||
|
||||
return uuids::to_string(generator());
|
||||
}
|
||||
|
||||
uint64_t Random()
|
||||
{
|
||||
std::random_device device;
|
||||
|
||||
@@ -14,5 +14,7 @@ std::string ToHex(std::byte* src, size_t len);
|
||||
|
||||
std::string HashPassword(const std::string& password);
|
||||
|
||||
std::string GenerateUUID();
|
||||
|
||||
uint64_t Random();
|
||||
} // namespace uad
|
||||
|
||||
Reference in New Issue
Block a user