diff --git a/sql/migration4.sql b/sql/migration4.sql index 9d943d6..e195ce7 100644 --- a/sql/migration4.sql +++ b/sql/migration4.sql @@ -8,7 +8,7 @@ BEGIN TRANSACTION; CREATE TABLE Auth ( AccountID INTEGER NOT NULL, Cookie TEXT NOT NULL, - Valid INTEGER NOT NULL, + Expires INTEGER DEFAULT 0 NOT NULL, FOREIGN KEY(AccountID) REFERENCES Accounts(AccountID) ON DELETE CASCADE, UNIQUE (AccountID) ); diff --git a/sql/tables.sql b/sql/tables.sql index 5a89ed2..70b3169 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -163,7 +163,7 @@ CREATE TABLE IF NOT EXISTS RedeemedCodes ( CREATE TABLE IF NOT EXISTS Auth ( AccountID INTEGER NOT NULL, Cookie TEXT NOT NULL, - Valid INTEGER DEFAULT 0 NOT NULL, + Expires INTEGER DEFAULT 0 NOT NULL, FOREIGN KEY(AccountID) REFERENCES Accounts(AccountID) ON DELETE CASCADE, UNIQUE (AccountID) ); diff --git a/src/db/login.cpp b/src/db/login.cpp index 1e1404a..824ac58 100644 --- a/src/db/login.cpp +++ b/src/db/login.cpp @@ -104,12 +104,12 @@ bool Database::checkCookie(int accountId, const char *tryCookie) { const char* sql_get = R"( SELECT Cookie FROM Auth - WHERE AccountID = ? AND Valid = 1; + WHERE AccountID = ? AND Expires > ?; )"; const char* sql_invalidate = R"( UPDATE Auth - SET Valid = 0 + SET Expires = 0 WHERE AccountID = ?; )"; @@ -117,6 +117,7 @@ bool Database::checkCookie(int accountId, const char *tryCookie) { sqlite3_prepare_v2(db, sql_get, -1, &stmt, NULL); sqlite3_bind_int(stmt, 1, accountId); + sqlite3_bind_int(stmt, 2, getTimestamp()); int rc = sqlite3_step(stmt); if (rc != SQLITE_ROW) { sqlite3_finalize(stmt);