#pragma once #include #include "Types.h" #include namespace VWeb { using ms = std::chrono::duration; struct SessionData { virtual ~SessionData() = default; template T *As() { return reinterpret_cast(this); } }; struct Session { std::string Id; long TTLSeconds = 1440; // 24 minutes 1440 seconds bool IsValid(); void Update(); void Remove(const std::string &key); bool Has(const std::string &key); Ref &operator[](const std::string &key) { return m_Data[key]; } void SetSessionData(const std::string &key, const Ref &data) { m_Data[key] = data; } bool ContainsData() { return !m_Data.empty(); } protected: std::chrono::time_point m_LastCall = std::chrono::system_clock::now(); std::unordered_map> m_Data; }; }