database functions
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
#ifndef DATABASE_HPP
|
||||
#define DATABASE_HPP
|
||||
#include "types.hpp"
|
||||
#include "timestamp.hpp"
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
|
||||
class PostgresDB {
|
||||
private:
|
||||
@@ -7,6 +12,26 @@ private:
|
||||
public:
|
||||
PostgresDB(const std::string& connection) : conn_str(connection) {}
|
||||
|
||||
User GetUser(const int uid);
|
||||
User GetUser(int uid);
|
||||
User GetUser(const std::string& username, const std::string& password);
|
||||
};
|
||||
void GetUser(User& user) { user = GetUser(user.uid);};
|
||||
|
||||
User CreateUser(const std::string& username, const std::string& password, bool is_system);
|
||||
void UpdateUserPassowrd(User& user, const std::string& password);
|
||||
void DeleteUser(const User& user);
|
||||
|
||||
void CreateMember(User& user, const std::string& name, const std::string& pronouns, const std::string& description);
|
||||
void UpdateMemberDescription(Member& member, const std::string& description);
|
||||
void UpdateMemberPronouns(Member& member, const std::string& pronouns);
|
||||
void UpdateMemberName(Member& member, const std::string& name);
|
||||
void DeleteMember(const Member& member);
|
||||
|
||||
void CreateAccessToken(User& user);
|
||||
void DeleteAccessToken(const User& user);
|
||||
|
||||
void StartFront(const User& user, const Member& member, const std::string& note = "", Timestamp start_time = std::chrono::system_clock::now());
|
||||
void EndFront(const User& user, const Member& member, Timestamp end_time = std::chrono::system_clock::now());
|
||||
std::vector<Front> GetFronts(const User& user, Timestamp start_time, std::optional<Timestamp> end_time = std::nullopt);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,12 @@
|
||||
#ifndef HASHING_HPP
|
||||
#define HASHING_HPP
|
||||
#include <string>
|
||||
|
||||
namespace hashing {
|
||||
std::string GenerateSetting(unsigned long cost = 0);
|
||||
std::string HashPassword(const std::string& password, const std::string& setting);
|
||||
bool VerifyPassword(const std::string& password, const std::string& stored_password);
|
||||
}
|
||||
std::string generate_token(size_t bytes = 32);
|
||||
}
|
||||
|
||||
#endif
|
||||
11
include/timestamp.hpp
Normal file
11
include/timestamp.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef TIMESTAMP_HPP
|
||||
#define TIMESTAMP_HPP
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
typedef std::chrono::system_clock::time_point Timestamp;
|
||||
|
||||
Timestamp ParseTimestamp(const std::string& ts);
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,8 @@
|
||||
#ifndef TYPES_HPP
|
||||
#define TYPES_HPP
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include "hashing.hpp"
|
||||
|
||||
struct AcessToken {
|
||||
@@ -52,4 +55,16 @@ struct User {
|
||||
const bool CheckPassword(const std::string& password) const {
|
||||
return hashing::VerifyPassword(password, password_hash);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct Front {
|
||||
int fid;
|
||||
int uid;
|
||||
Member *member;
|
||||
std::string note;
|
||||
std::chrono::system_clock::time_point start_time;
|
||||
bool is_active;
|
||||
std::chrono::system_clock::time_point end_time;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user