generated from Sithas/conan_template
45 lines
993 B
C++
45 lines
993 B
C++
#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,
|
|
const std::string& auth_token)
|
|
{
|
|
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::HasAuthorized(const std::string& auth_token)
|
|
{
|
|
return auth_tokens_to_users_uuids_.count(auth_token) > 0;
|
|
}
|
|
|
|
std::string_view MemoryAuthDAO::GetUUID(const std::string& auth_token)
|
|
{
|
|
return auth_tokens_to_users_uuids_.at(auth_token);
|
|
}
|
|
|
|
bool MemoryAuthDAO::Logout(const std::string& auth_token)
|
|
{
|
|
if (!HasAuthorized(auth_token)) return false;
|
|
|
|
string user_uuid = auth_tokens_to_users_uuids_[auth_token];
|
|
|
|
users_uuids_to_auth_tokens_.erase(user_uuid);
|
|
auth_tokens_to_users_uuids_.erase(auth_token);
|
|
|
|
return true;
|
|
}
|
|
}
|