aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/managers/TokenManager.hpp
blob: ead02275960ab515793e4b1d579b7688036fc971 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include <memory>
#include <chrono>
#include <any>
#include <unordered_map>
#include <string>

class CUUIDToken {
  public:
    CUUIDToken(const std::string& uuid_, std::any data_, std::chrono::system_clock::duration expires);

    std::string getUUID();

    std::any    data;

  private:
    std::string                           uuid;

    std::chrono::system_clock::time_point expiresAt;

    friend class CTokenManager;
};

class CTokenManager {
  public:
    std::string                 registerNewToken(std::any data, std::chrono::system_clock::duration expires);
    std::string                 getRandomUUID();

    std::shared_ptr<CUUIDToken> getToken(const std::string& uuid);
    void                        removeToken(std::shared_ptr<CUUIDToken> token);

  private:
    std::unordered_map<std::string, std::shared_ptr<CUUIDToken>> m_mTokens;
};

inline std::unique_ptr<CTokenManager> g_pTokenManager;