aboutsummaryrefslogtreecommitdiff
path: root/backend/info.php
blob: 01f3044e9b645927d1875c4125914b72d1674547 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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" }';

?>