DAO - Полное завершение класса

This commit is contained in:
Антон
2025-09-06 12:10:47 +03:00
parent 0838b96a27
commit b012faf1b6
5 changed files with 95 additions and 1 deletions
+41
View File
@@ -0,0 +1,41 @@
#include <boost/uuid.hpp>
#include "MemoryAuthDAO.h"
using namespace std;
namespace uad
{
MemoryAuthDAO::MemoryAuthDAO(mysqlx::Session& session): session_(session)
{
}
std::string MemoryAuthDAO::Login(const std::string& registrated_user_uuid)
{
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;
return auth_token;
}
bool MemoryAuthDAO::HasAuthorizedUser(const std::string& auth_token)
{
return auth_tokens_to_users_uuids_.count(auth_token) > 0;
}
bool MemoryAuthDAO::Logout(const std::string& auth_token)
{
string user_uuid = auth_tokens_to_users_uuids_[auth_token];
if (!HasAuthorizedUser()) return false;
users_uuids_to_auth_tokens_.erase(user_uuid);
auth_tokens_to_users_uuids_.erase(auth_token);
return true;
}
}