schema directory for all datastructures of database, add-list assets requests, not tested
This commit is contained in:
parent
d33ec5def8
commit
4df8d4319e
15 changed files with 306 additions and 62 deletions
|
@ -12,6 +12,8 @@
|
|||
#include "handler/register.h"
|
||||
#include "handler/login.h"
|
||||
#include "handler/poll.h"
|
||||
#include "handler/listassets.h"
|
||||
#include "handler/addasset.h"
|
||||
|
||||
#include "taskmanager/route.h"
|
||||
|
||||
|
@ -32,7 +34,7 @@ constexpr uint32_t hashMemoryCost = 65536;
|
|||
|
||||
constexpr uint8_t currentDbVesion = 1;
|
||||
|
||||
Server::Server():
|
||||
Server::Server ():
|
||||
std::enable_shared_from_this<Server>(),
|
||||
terminating(false),
|
||||
requestCount(0),
|
||||
|
@ -59,14 +61,16 @@ Server::Server():
|
|||
db->migrate(currentDbVesion);
|
||||
}
|
||||
|
||||
Server::~Server() {}
|
||||
Server::~Server () {}
|
||||
|
||||
void Server::run(int socketDescriptor) {
|
||||
void Server::run (int socketDescriptor) {
|
||||
router->addRoute(std::make_unique<Handler::Info>());
|
||||
router->addRoute(std::make_unique<Handler::Env>());
|
||||
router->addRoute(std::make_unique<Handler::Register>(shared_from_this()));
|
||||
router->addRoute(std::make_unique<Handler::Login>(shared_from_this()));
|
||||
router->addRoute(std::make_unique<Handler::Poll>(shared_from_this()));
|
||||
router->addRoute(std::make_unique<Handler::ListAssets>(shared_from_this()));
|
||||
router->addRoute(std::make_unique<Handler::AddAsset>(shared_from_this()));
|
||||
|
||||
taskManager->start();
|
||||
scheduler->start();
|
||||
|
@ -82,7 +86,7 @@ void Server::run(int socketDescriptor) {
|
|||
}
|
||||
}
|
||||
|
||||
void Server::handleRequest(std::unique_ptr<Request> request) {
|
||||
void Server::handleRequest (std::unique_ptr<Request> request) {
|
||||
++requestCount;
|
||||
if (!serverName) {
|
||||
try {
|
||||
|
@ -102,7 +106,7 @@ void Server::handleRequest(std::unique_ptr<Request> request) {
|
|||
taskManager->schedule(std::move(route));
|
||||
}
|
||||
|
||||
std::string Server::generateRandomString(std::size_t length) {
|
||||
std::string Server::generateRandomString (std::size_t length) {
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<uint8_t> distribution(0, std::strlen(randomChars) - 1);
|
||||
|
@ -114,7 +118,7 @@ std::string Server::generateRandomString(std::size_t length) {
|
|||
return result;
|
||||
}
|
||||
|
||||
unsigned int Server::registerAccount(const std::string& login, const std::string& password) {
|
||||
unsigned int Server::registerAccount (const std::string& login, const std::string& password) {
|
||||
std::size_t encSize = argon2_encodedlen(
|
||||
hashIterations, hashMemoryCost,
|
||||
hashParallel, saltSize, hashSize, Argon2_id
|
||||
|
@ -138,7 +142,7 @@ unsigned int Server::registerAccount(const std::string& login, const std::string
|
|||
return db->registerAccount(login, hash);
|
||||
}
|
||||
|
||||
bool Server::validatePassword(const std::string& login, const std::string& password) {
|
||||
bool Server::validatePassword (const std::string& login, const std::string& password) {
|
||||
DB::Resource db = pool->request();
|
||||
std::string hash = db->getAccountHash(login);
|
||||
|
||||
|
@ -155,7 +159,7 @@ bool Server::validatePassword(const std::string& login, const std::string& passw
|
|||
}
|
||||
}
|
||||
|
||||
Session& Server::openSession(const std::string& login) {
|
||||
Session& Server::openSession (const std::string& login) {
|
||||
std::string accessToken, renewToken;
|
||||
DB::Session s;
|
||||
s.id = 0;
|
||||
|
@ -197,3 +201,8 @@ Session& Server::getSession (const std::string& accessToken) {
|
|||
);
|
||||
return *session.get();
|
||||
}
|
||||
|
||||
|
||||
DB::Resource Server::getDatabase () {
|
||||
return pool->request();
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
bool validatePassword(const std::string& login, const std::string& password);
|
||||
Session& openSession(const std::string& login);
|
||||
Session& getSession(const std::string& accessToken);
|
||||
DB::Resource getDatabase();
|
||||
|
||||
private:
|
||||
void handleRequest(std::unique_ptr<Request> request);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue