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
|
@ -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