From ad8f293645327af40de6323bed21b929056ab2c0 Mon Sep 17 00:00:00 2001 From: hitlerrip Date: Wed, 30 Jul 2025 10:22:01 +0200 Subject: info api added info api, similar to contrib api, that returns information about a user based on their token. this is required for how i want to build the frontend --- backend/info.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 backend/info.php diff --git a/backend/info.php b/backend/info.php new file mode 100644 index 0000000..01f3044 --- /dev/null +++ b/backend/info.php @@ -0,0 +1,47 @@ + + * licensed under AGPLv3-or-later; see LICENSE.md for more information + */ + +header('Content-Type: application/json; charset=UTF-8'); + +try { + $pdo = new PDO("mysql:host=127.0.0.1;dbname=hitlerclicker", "root", "aA1234Aa"); +} catch(PDOException $e) { + die('{ "status": "database offline" }'); +}; + +$wrkarr = []; +$ifarr = [ "token" ]; +$postjson = json_decode(file_get_contents('php://input'), true); +foreach ($ifarr as $i): + if (isset($postjson[$i])): + $newarr = [ + "$i" => "$postjson[$i]", + ]; + $wrkarr = array_merge($wrkarr, $newarr); + endif; +endforeach; + +if (!isset($wrkarr["token"]) || trim($wrkarr["token"]) == ""): + die('{ "status": "token was not provided.\ncould not return information." }'); +else: + + $query = $pdo->prepare("SELECT name, team, clicks FROM users WHERE token LIKE ?"); + $query -> execute([$wrkarr["token"]]); + $found = $query->fetch(PDO::FETCH_ASSOC); + if ($found): + + die("{ \"status\": \"success\", \"name\": \"$found[name]\", \"team\": \"$found[team]\", \"clicks\": \"$found[clicks]\" }"); + + else: + die('{ "status": "token does not exist in the database." }'); + endif; + +endif; + +echo '{ "status": "online" }'; + +?> -- cgit v1.2.3