From 8171f0db664ebcc547a56fdd57d8881c4963caa5 Mon Sep 17 00:00:00 2001 From: Mario <100047175+Mariopizza1@users.noreply.github.com> Date: Mon, 13 Feb 2023 11:12:28 +0200 Subject: [PATCH] Create getauthtoken.php --- getauthtoken.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 getauthtoken.php diff --git a/getauthtoken.php b/getauthtoken.php new file mode 100644 index 0000000..5f69679 --- /dev/null +++ b/getauthtoken.php @@ -0,0 +1,44 @@ +isLoggedIn()) { + header('location: /login'); + exit; +} +$placeid = $_GET['placeid']; +if (!isset($placeid)) { + echo "No placeid"; + exit; +} +$username = $user->getUsername(); +$id = $user->getID($con, $user->getUsername()); +function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[random_int(0, $charactersLength - 1)]; + } + return $randomString; +} // pls don't hurt me +$checkifuser = $con->prepare('SELECT COUNT(*) FROM games WHERE id=:placeid'); +$checkifuser->bindParam(':placeid', $placeid); +$checkifuser->execute(); +$momentoftruth = $checkifuser->fetchColumn(); +if ($momentoftruth == 1) { + $token = generateRandomString(500); + $fbi = $con->prepare('INSERT INTO tokens (token, placeid, userid) VALUES (:token, :placeid, :userid)'); + $fbi->bindParam(':token', $token); + $fbi->bindParam(':placeid', $placeid); + $fbi->bindParam(':userid', $id); + $fbi->execute(); + echo $token; +} else { + echo 'No placeId found'; + exit; +} +?>