diff options
author | hitlerrip <git@hitler.rip> | 2025-07-29 21:29:50 +0200 |
---|---|---|
committer | hitlerrip <git@hitler.rip> | 2025-07-29 21:29:50 +0200 |
commit | 423c37e0254a0f7a5b4ef5326da4379b7c65792d (patch) | |
tree | 25d1fa9ec97012d2c6d5961b92e29d38c73cb00a | |
parent | 0dbbf0b26f24afa0c253e42682bba19ce7bd4cb6 (diff) | |
download | hitler-clicker-423c37e0254a0f7a5b4ef5326da4379b7c65792d.tar.gz hitler-clicker-423c37e0254a0f7a5b4ef5326da4379b7c65792d.tar.bz2 hitler-clicker-423c37e0254a0f7a5b4ef5326da4379b7c65792d.zip |
contirb api
added api that returns a specific users contributed clicks and their
team
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | backend/contrib.php | 47 |
2 files changed, 47 insertions, 1 deletions
@@ -39,7 +39,6 @@ curl -X POST -d '{ "key": "value" }' http://localhost:8000/yourapifile.php ### Backend -- add api that returns a specific users clicks - add name and password change - add anonymous clicking for a team diff --git a/backend/contrib.php b/backend/contrib.php new file mode 100644 index 0000000..47538da --- /dev/null +++ b/backend/contrib.php @@ -0,0 +1,47 @@ +<?php +/* hitler-clicker + * api for seeing contributions of a specific user + * © 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 = [ "name" ]; +$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["name"]) || trim($wrkarr["name"]) == ""): + die('{ "status": "name was not provided.\nuse the rank api if you want to see all users or the index api if you want to see all teams." }'); +else: + + $query = $pdo->prepare("SELECT name, team, clicks FROM users WHERE name LIKE ?"); + $query -> execute([$wrkarr["name"]]); + $found = $query->fetch(PDO::FETCH_ASSOC); + if ($found): + + die("{ \"status\": \"success\", \"team\": \"$found[team]\", \"clicks\": \"$found[clicks]\" }"); + + else: + die('{ "status": "name does not exist in the database." }'); + endif; + +endif; + +echo '{ "status": "online" }'; + +?> |