generated from Sithas/conan_template
DAO - Полное завершение класса
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user