[Loginserver] Update ticket login table structure (#3703)

* Updates login table to support tickets in a way that makes more sense.

* Change to snake_case as requested by Akka

---------

Co-authored-by: KimLS <KimLS@peqtgc.com>
This commit is contained in:
Alex 2023-11-22 00:56:47 -08:00 committed by GitHub
parent 4c8d68c24b
commit 2bd94ab7a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 28 deletions

View File

@ -121,43 +121,25 @@ bool Database::GetLoginTokenDataFromToken(
std::string &user std::string &user
) )
{ {
auto query = fmt::format( auto query = fmt::format("SELECT login_server, username, account_id FROM login_tickets WHERE expires > NOW()"
"SELECT tbllogintokens.Id, tbllogintokens.IpAddress, tbllogintokenclaims.Name, tbllogintokenclaims.Value FROM tbllogintokens " " AND id='{0}' AND ip_address='{1}' LIMIT 1",
"JOIN tbllogintokenclaims ON tbllogintokens.Id = tbllogintokenclaims.TokenId WHERE tbllogintokens.Expires > NOW() "
"AND tbllogintokens.Id='{0}' AND tbllogintokens.IpAddress='{1}'",
Strings::Escape(token), Strings::Escape(token),
Strings::Escape(ip) Strings::Escape(ip));
);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (results.RowCount() == 0 || !results.Success()) { if (results.RowCount() == 0 || !results.Success()) {
return false; return false;
} }
bool found_username = false; for (auto row = results.begin(); row != results.end(); ++row) {
bool found_login_id = false; db_loginserver = row[0];
bool found_login_server_name = false; user = row[1];
for (auto row = results.begin(); row != results.end(); ++row) { db_account_id = Strings::ToUnsignedInt(row[2]);
if (strcmp(row[2], "username") == 0) {
user = row[3];
found_username = true;
continue;
}
if (strcmp(row[2], "login_server_id") == 0) { return true;
db_account_id = Strings::ToUnsignedInt(row[3]);
found_login_id = true;
continue;
}
if (strcmp(row[2], "login_server_name") == 0) {
db_loginserver = row[3];
found_login_server_name = true;
continue;
}
} }
return found_username && found_login_id && found_login_server_name; return false;
} }
/** /**

View File

@ -0,0 +1,11 @@
DROP TABLE IF EXISTS `login_tickets`;
CREATE TABLE `login_tickets` (
`id` VARCHAR(128) NOT NULL,
`login_server` TEXT NOT NULL,
`username` TEXT NOT NULL,
`account_id` INT(10) UNSIGNED NOT NULL,
`ip_address` VARCHAR(45) NOT NULL,
`expires` DATETIME NOT NULL,
PRIMARY KEY (`id`) USING BTREE
)
ENGINE=InnoDB;