From 5fc857449011f76ed7677aad40576790310d23e1 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 20 Apr 2025 16:06:19 +0500 Subject: feat: moved from SQLite to MySQL --- public/account/login/index.php | 3 +-- public/account/login/twitch.php | 48 ++++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 29 deletions(-) (limited to 'public/account/login') diff --git a/public/account/login/index.php b/public/account/login/index.php index 146fde9..e104a88 100644 --- a/public/account/login/index.php +++ b/public/account/login/index.php @@ -1,7 +1,6 @@ diff --git a/public/account/login/twitch.php b/public/account/login/twitch.php index ff2fe51..7866eb5 100644 --- a/public/account/login/twitch.php +++ b/public/account/login/twitch.php @@ -1,8 +1,9 @@ prepare("SELECT id, user_id FROM connections WHERE alias_id = :alias_id AND platform = 'twitch'"); -$stmt->bindValue("alias_id", $twitch_user["id"]); - -$results = $stmt->execute(); +$stmt = $db->prepare("SELECT id, user_id FROM connections WHERE alias_id = ? AND platform = 'twitch'"); +$stmt->execute([$twitch_user["id"]]); $user_id = ""; $user_secret_key = ""; $user_name = ""; -if ($row = $results->fetchArray()) { +if ($row = $stmt->fetch()) { $id = $row["id"]; $user_id = $row["user_id"]; - $stmt = $db->prepare("SELECT * FROM users WHERE id = :id"); - $stmt->bindValue(":id", $id); - $results = $stmt->execute(); + $stmt = $db->prepare("SELECT * FROM users WHERE id = ?"); + $stmt->execute([$user_id]); - if ($row = $results->fetchArray()) { + if ($row = $stmt->fetch()) { $user_name = $row["username"]; $user_secret_key = $row["secret_key"]; $user_id = $row["id"]; } else { - $db->close(); + $db = null; echo "Connection found, but not user?"; exit; } @@ -99,32 +97,28 @@ if ($row = $results->fetchArray()) { $user_secret_key = generate_random_string(32); $user_name = $twitch_user["login"]; - $stmt = $db->prepare("INSERT INTO users(username, secret_key) VALUES (:username, :secret_key)"); - $stmt->bindValue(":username", $user_name); - $stmt->bindValue(":secret_key", $user_secret_key); - if (!$stmt->execute()) { - $db->close(); + $stmt = $db->prepare("INSERT INTO users(username, secret_key) VALUES (?, ?)"); + if (!$stmt->execute([$user_name, $user_secret_key])) { + $db = null; echo "Failed to create a user"; exit; } - $user_id = $db->lastInsertRowID(); + $user_id = $db->lastInsertId(); - $stmt = $db->prepare("INSERT INTO connections(user_id, alias_id, platform, data) VALUES (:user_id, :alias_id, 'twitch', :data)"); - $stmt->bindValue(":user_id", $user_id); - $stmt->bindValue(":alias_id", $twitch_user["id"]); - $stmt->bindValue( - ":data", + $stmt = $db->prepare("INSERT INTO connections(user_id, alias_id, platform, data) VALUES (?, ?, 'twitch', ?)"); + $stmt->execute([ + $user_id, + $twitch_user["id"], $_SESSION["twitch_access_token"] . ":" . $_SESSION["twitch_refresh_token"] . ":" . $_SESSION["twitch_expires_on"] - ); - $stmt->execute(); + ]); } $_SESSION["user_id"] = $user_id; $_SESSION["user_name"] = $user_name; setcookie("secret_key", $user_secret_key, time() + 86400 * 30, "/"); -$db->close(); +$db = null; // downloading profile picture $path = "../../static/userdata/avatars"; -- cgit v1.2.3