33 lines
669 B
C++
33 lines
669 B
C++
#ifndef __SESSIONHANDLER_H__
|
|
#define __SESSIONHANDLER_H__
|
|
|
|
#include "Session.hpp"
|
|
#include <optional>
|
|
#include <thread>
|
|
#include <unordered_map>
|
|
#include <string>
|
|
|
|
namespace login {
|
|
|
|
class SessionHandler {
|
|
|
|
public:
|
|
SessionHandler();
|
|
~SessionHandler();
|
|
|
|
std::optional<std::string> createSession(int userId);
|
|
|
|
// return the user id if the user is logged in
|
|
std::optional<int> isSessionValid(const std::string& sessionId);
|
|
private:
|
|
void cleanupWorker();
|
|
std::thread cleanupThread;
|
|
std::atomic<bool> stopCleanupThread;
|
|
std::mutex sessionMutex;
|
|
|
|
std::unordered_map<std::string, Session> sessions;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // __SESSIONHANDLER_H__
|