scheduler canceling, sessiion query, didn't test yet!
This commit is contained in:
parent
544db92b6e
commit
5d765958e5
15 changed files with 166 additions and 21 deletions
|
@ -18,3 +18,7 @@ DB::EmptyResult::EmptyResult(const std::string& text):
|
|||
DB::NoLogin::NoLogin(const std::string& text):
|
||||
EmptyResult(text)
|
||||
{}
|
||||
|
||||
DB::NoSession::NoSession (const std::string& text):
|
||||
EmptyResult(text)
|
||||
{}
|
||||
|
|
|
@ -26,4 +26,9 @@ class NoLogin : public EmptyResult {
|
|||
public:
|
||||
explicit NoLogin(const std::string& text);
|
||||
};
|
||||
|
||||
class NoSession : public EmptyResult {
|
||||
public:
|
||||
explicit NoSession(const std::string& text);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -9,6 +9,13 @@
|
|||
#include <stdint.h>
|
||||
|
||||
namespace DB {
|
||||
struct Session {
|
||||
unsigned int id;
|
||||
unsigned int owner;
|
||||
std::string accessToken;
|
||||
std::string renewToken;
|
||||
};
|
||||
|
||||
class Interface {
|
||||
public:
|
||||
enum class Type {
|
||||
|
@ -40,6 +47,7 @@ public:
|
|||
virtual unsigned int registerAccount(const std::string& login, const std::string& hash) = 0;
|
||||
virtual std::string getAccountHash(const std::string& login) = 0;
|
||||
virtual unsigned int createSession(const std::string& login, const std::string& access, const std::string& renew) = 0;
|
||||
virtual Session findSession(const std::string& accessToken) = 0;
|
||||
|
||||
protected:
|
||||
Interface(Type type);
|
||||
|
|
|
@ -20,6 +20,7 @@ constexpr const char* assignRoleQuery = "INSERT INTO roleBindings (`account`, `r
|
|||
constexpr const char* selectHash = "SELECT password FROM accounts where login = ?";
|
||||
constexpr const char* createSessionQuery = "INSERT INTO sessions (`owner`, `access`, `renew`, `persist`, `device`)"
|
||||
" SELECT accounts.id, ?, ?, true, ? FROM accounts WHERE accounts.login = ?";
|
||||
constexpr const char* selectSession = "SELECT id, owner, renew FROM sessions where access = ?";
|
||||
|
||||
static const std::filesystem::path buildSQLPath = "database";
|
||||
|
||||
|
@ -298,6 +299,24 @@ unsigned int DB::MySQL::lastInsertedId() {
|
|||
else
|
||||
throw std::runtime_error(std::string("Querying last inserted id returned no rows"));
|
||||
}
|
||||
|
||||
DB::Session DB::MySQL::findSession(const std::string& accessToken) {
|
||||
std::string a = accessToken;
|
||||
MYSQL* con = &connection;
|
||||
|
||||
Statement session(con, selectSession);
|
||||
session.bind(a.data(), MYSQL_TYPE_STRING);
|
||||
|
||||
std::vector<std::vector<std::any>> result = session.fetchResult();
|
||||
if (result.empty())
|
||||
throw NoSession("Couldn't find session with token " + a);
|
||||
|
||||
DB::Session res;
|
||||
res.id = std::any_cast<unsigned int>(result[0][0]);
|
||||
res.owner = std::any_cast<unsigned int>(result[0][1]);
|
||||
res.renewToken = std::any_cast<const std::string&>(result[0][2]);
|
||||
res.accessToken = a;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
unsigned int registerAccount(const std::string& login, const std::string& hash) override;
|
||||
std::string getAccountHash(const std::string& login) override;
|
||||
unsigned int createSession(const std::string& login, const std::string& access, const std::string& renew) override;
|
||||
Session findSession(const std::string& accessToken) override;
|
||||
|
||||
private:
|
||||
void executeFile(const std::filesystem::path& relativePath);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue