types and db setup
This commit is contained in:
12
include/database.hpp
Normal file
12
include/database.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "types.hpp"
|
||||
|
||||
class PostgresDB {
|
||||
private:
|
||||
std::string conn_str;
|
||||
|
||||
public:
|
||||
PostgresDB(const std::string& connection) : conn_str(connection) {}
|
||||
|
||||
User GetUser(const int uid);
|
||||
User GetUser(const std::string& username, const std::string& password);
|
||||
};
|
||||
7
include/hashing.hpp
Normal file
7
include/hashing.hpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#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);
|
||||
}
|
||||
55
include/types.hpp
Normal file
55
include/types.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "hashing.hpp"
|
||||
|
||||
struct AcessToken {
|
||||
int uid;
|
||||
std::string token;
|
||||
|
||||
const bool operator==(const AcessToken& other) const {
|
||||
return uid == other.uid && token == other.token;
|
||||
}
|
||||
|
||||
const bool operator==(const std::string& token) const {
|
||||
return token == this->token;
|
||||
}
|
||||
};
|
||||
|
||||
struct Member {
|
||||
int mid;
|
||||
int sid;
|
||||
std::string name;
|
||||
std::string pronouns;
|
||||
std::string description;
|
||||
|
||||
const bool operator==(const Member& other) const {
|
||||
return mid == other.mid;
|
||||
}
|
||||
};
|
||||
|
||||
struct System {
|
||||
int sid;
|
||||
int uid;
|
||||
std::vector<Member> members;
|
||||
|
||||
const bool operator==(const System& other) const {
|
||||
return sid == other.sid;
|
||||
}
|
||||
};
|
||||
|
||||
struct User {
|
||||
int uid;
|
||||
std::string username;
|
||||
std::string password_hash;
|
||||
bool is_system;
|
||||
System *system;
|
||||
AcessToken *accesstoken;
|
||||
|
||||
const bool operator==(const User& other) const {
|
||||
return uid == other.uid;
|
||||
}
|
||||
|
||||
const bool CheckPassword(const std::string& password) const {
|
||||
return hashing::VerifyPassword(password, password_hash);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user