47 lines
1.7 KiB
C++
47 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <chrono>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include "Definitions.h"
|
|
|
|
namespace ts {
|
|
namespace server {
|
|
class TSServer;
|
|
}
|
|
|
|
namespace token {
|
|
enum TokenType : uint8_t {
|
|
TOKEN_SERVER,
|
|
TOKEN_CHANNEL
|
|
};
|
|
struct TokenEntry {
|
|
TokenEntry(const std::string &token, TokenType type, GroupId groupId, ChannelId channelId, const std::chrono::time_point<std::chrono::system_clock> &created, const std::string &description);
|
|
|
|
std::string token;
|
|
TokenType type; //token_type
|
|
GroupId groupId; //token_id1
|
|
ChannelId channelId; //token_id2
|
|
std::chrono::time_point<std::chrono::system_clock> created;
|
|
std::string description;
|
|
};
|
|
|
|
class TokenManager {
|
|
public:
|
|
TokenManager(server::TSServer*);
|
|
~TokenManager();
|
|
bool loadTokens();
|
|
|
|
std::vector<std::shared_ptr<TokenEntry>> avariableTokes(){ return tokens; }
|
|
std::shared_ptr<TokenEntry> findToken(std::string);
|
|
std::shared_ptr<TokenEntry> createToken(TokenType, GroupId, std::string, ChannelId = 0, std::string token = "");
|
|
bool deleteToke(const std::string&);
|
|
private:
|
|
int loadTokenFromDb(int length, char** values, char** columns);
|
|
server::TSServer* handle;
|
|
std::vector<std::shared_ptr<TokenEntry>> tokens;
|
|
};
|
|
}
|
|
}
|
|
DEFINE_VARIABLE_TRANSFORM(ts::token::TokenType, VARTYPE_INT, std::to_string((uint8_t) in), static_cast<ts::token::TokenType>(in.as<uint8_t>())); |