diff options
Diffstat (limited to 'public/account')
| -rw-r--r-- | public/account/delete.php | 10 | ||||
| -rw-r--r-- | public/account/login/twitch.php | 16 |
2 files changed, 9 insertions, 17 deletions
diff --git a/public/account/delete.php b/public/account/delete.php index ecfcc80..4459edb 100644 --- a/public/account/delete.php +++ b/public/account/delete.php @@ -12,15 +12,7 @@ if (!isset($_SESSION["user_id"])) { $id = $_SESSION["user_id"]; $db = new PDO(DB_URL, DB_USER, DB_PASS); - -$stmt = $db->prepare("UPDATE emotes SET uploaded_by = NULL WHERE uploaded_by = ?"); -$stmt->execute([$id]); - -$stmt = $db->prepare("DELETE FROM connections WHERE user_id = ?"); -$stmt->execute([$id]); - -$stmt = $db->prepare("DELETE FROM users WHERE id = ?"); -$stmt->execute([$id]); +$db->prepare("DELETE FROM users WHERE id = ?")->execute([$id]); session_unset(); session_destroy(); diff --git a/public/account/login/twitch.php b/public/account/login/twitch.php index dfd319f..f322f42 100644 --- a/public/account/login/twitch.php +++ b/public/account/login/twitch.php @@ -69,9 +69,9 @@ if (empty($twitch_user["data"])) { $twitch_user = $twitch_user["data"][0]; // saving it -$_SESSION["twitch_access_token"] = $response["access_token"]; -$_SESSION["twitch_refresh_token"] = $response["refresh_token"]; -$_SESSION["twitch_expires_on"] = time() + intval($response["expires_in"]); +$twitch_access_token = $response["access_token"]; +$twitch_refresh_token = $response["refresh_token"]; +$twitch_expires_on = time() + intval($response["expires_in"]); $db = new PDO(DB_URL, DB_USER, DB_PASS); @@ -102,21 +102,21 @@ if ($row = $stmt->fetch()) { } else { $user_secret_key = generate_random_string(32); $user_name = $twitch_user["login"]; + $user_id = bin2hex(random_bytes(16)); - $stmt = $db->prepare("INSERT INTO users(username, secret_key) VALUES (?, ?)"); - if (!$stmt->execute([$user_name, $user_secret_key])) { + + $stmt = $db->prepare("INSERT INTO users(id, username, secret_key) VALUES (?, ?, ?)"); + if (!$stmt->execute([$user_id, $user_name, $user_secret_key])) { $db = null; echo "Failed to create a user"; exit; } - $user_id = $db->lastInsertId(); - $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"] + sprintf("%s:%s:%s", $twitch_access_token, $twitch_refresh_token, $twitch_expires_on) ]); } |
