32 lines
715 B
C++
32 lines
715 B
C++
#ifndef __SESSION_H__
|
|
#define __SESSION_H__
|
|
|
|
#include <chrono>
|
|
|
|
namespace login {
|
|
|
|
class Session {
|
|
|
|
public:
|
|
static constexpr auto SESSION_LIFETIME = std::chrono::minutes(30);
|
|
static constexpr size_t SESSION_ID_SIZE = 32;
|
|
|
|
Session(int userId);
|
|
|
|
// extend the session lifetime
|
|
void extend();
|
|
void extend(std::chrono::time_point<std::chrono::steady_clock> now);
|
|
|
|
bool isExpired(std::chrono::time_point<std::chrono::steady_clock> now);
|
|
|
|
const int userId() { return m_userId; }
|
|
const std::chrono::steady_clock::time_point expiresAt() {return m_expiresAt;}
|
|
|
|
private:
|
|
const int m_userId;
|
|
std::chrono::steady_clock::time_point m_expiresAt;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // __SESSION_H__
|