some ideas about database structure, began assets fetching request
This commit is contained in:
parent
a1ab1339e3
commit
d33ec5def8
13 changed files with 251 additions and 45 deletions
|
@ -157,25 +157,26 @@ bool Server::validatePassword(const std::string& login, const std::string& passw
|
|||
|
||||
Session& Server::openSession(const std::string& login) {
|
||||
std::string accessToken, renewToken;
|
||||
unsigned int sessionId = 0;
|
||||
DB::Session s;
|
||||
s.id = 0;
|
||||
int counter = 10;
|
||||
do {
|
||||
try {
|
||||
accessToken = generateRandomString(32);
|
||||
renewToken = generateRandomString(32);
|
||||
DB::Resource db = pool->request();
|
||||
sessionId = db->createSession(login, accessToken, renewToken);
|
||||
s = db->createSession(login, accessToken, renewToken);
|
||||
break;
|
||||
} catch (const DB::Duplicate& e) {
|
||||
std::cout << "Duplicate on creating session, trying again with different tokens";
|
||||
}
|
||||
} while (--counter != 0);
|
||||
|
||||
if (sessionId == 0)
|
||||
if (s.id == 0)
|
||||
throw std::runtime_error("Couldn't create session, ran out of attempts");
|
||||
|
||||
std::unique_ptr<Session>& session = sessions[accessToken]
|
||||
= std::make_unique<Session>(scheduler, sessionId, accessToken, renewToken, pollTimout);
|
||||
= std::make_unique<Session>(scheduler, s.id, s.owner, s.accessToken, s.renewToken, pollTimout);
|
||||
return *session.get();
|
||||
}
|
||||
|
||||
|
@ -189,6 +190,7 @@ Session& Server::getSession (const std::string& accessToken) {
|
|||
std::unique_ptr<Session>& session = sessions[accessToken] = std::make_unique<Session>(
|
||||
scheduler,
|
||||
s.id,
|
||||
s.owner,
|
||||
s.accessToken,
|
||||
s.renewToken,
|
||||
pollTimout
|
||||
|
|
|
@ -8,12 +8,14 @@
|
|||
Session::Session(
|
||||
std::weak_ptr<TM::Scheduler> scheduler,
|
||||
unsigned int id,
|
||||
unsigned int owner,
|
||||
const std::string& access,
|
||||
const std::string& renew,
|
||||
unsigned int timeout
|
||||
):
|
||||
scheduler(scheduler),
|
||||
id(id),
|
||||
owner(owner),
|
||||
scheduler(scheduler),
|
||||
access(access),
|
||||
renew(renew),
|
||||
polling(nullptr),
|
||||
|
|
|
@ -13,26 +13,29 @@ public:
|
|||
Session(
|
||||
std::weak_ptr<TM::Scheduler> scheduler,
|
||||
unsigned int id,
|
||||
unsigned int owner,
|
||||
const std::string& access,
|
||||
const std::string& renew,
|
||||
unsigned int timeout
|
||||
);
|
||||
Session(const Session&) = delete;
|
||||
Session(Session&& other);
|
||||
Session(Session&& other) = delete;
|
||||
~Session();
|
||||
Session& operator = (const Session&) = delete;
|
||||
Session& operator = (Session&& other);
|
||||
Session& operator = (Session&& other) = delete;
|
||||
|
||||
std::string getAccessToken() const;
|
||||
std::string getRenewToken() const;
|
||||
void accept(std::unique_ptr<Request> request) override;
|
||||
|
||||
const unsigned int id;
|
||||
const unsigned int owner;
|
||||
|
||||
private:
|
||||
void onTimeout();
|
||||
|
||||
private:
|
||||
std::weak_ptr<TM::Scheduler> scheduler;
|
||||
unsigned int id;
|
||||
std::string access;
|
||||
std::string renew;
|
||||
std::unique_ptr<Request> polling;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue