aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhitlerrip <git@hitler.rip>2025-07-30 10:22:01 +0200
committerhitlerrip <git@hitler.rip>2025-07-30 10:22:01 +0200
commitad8f293645327af40de6323bed21b929056ab2c0 (patch)
tree71aca076122a2a184a6ee2b37951e0f094424707
parent33578dfaa50ed79b6a96f0b568e85812221e0563 (diff)
downloadhitler-clicker-ad8f293645327af40de6323bed21b929056ab2c0.tar.gz
hitler-clicker-ad8f293645327af40de6323bed21b929056ab2c0.tar.bz2
hitler-clicker-ad8f293645327af40de6323bed21b929056ab2c0.zip
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
-rw-r--r--backend/info.php47
1 files changed, 47 insertions, 0 deletions
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 @@
+<?php
+/* hitler-clicker
+ * api to return information on a user based on token
+ * © 2025 hitler.rip <git@hitler.rip>
+ * 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" }';
+
+?>