From 0e13f77e05878aea20b6f05afd418bd97d1a9365 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Mon, 1 May 2017 14:38:36 -0600 Subject: [PATCH] Add option to get user info by ID, not name --- api.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/api.php b/api.php index f973d23..43f72ec 100644 --- a/api.php +++ b/api.php @@ -49,11 +49,23 @@ switch ($VARS['action']) { } break; case "userinfo": - if (user_exists($VARS['username'])) { - $data = $database->select("accounts", ["uid", "realname (name)", "email", "phone" => ["phone1 (1)", "phone2 (2)"]], ["username" => $VARS['username']])[0]; - exit(json_encode(["status" => "OK", "data" => $data])); + if (!is_empty($VARS['username'])) { + if (user_exists($VARS['username'])) { + $data = $database->select("accounts", ["uid", "username", "realname (name)", "email", "phone" => ["phone1 (1)", "phone2 (2)"]], ["username" => $VARS['username']])[0]; + exit(json_encode(["status" => "OK", "data" => $data])); + } else { + exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + } + } else if (!is_empty($VARS['uid'])) { + if ($database->has('accounts', ['uid' => $VARS['uid']])) { + $data = $database->select("accounts", ["uid", "username", "realname (name)", "email", "phone" => ["phone1 (1)", "phone2 (2)"]], ["uid" => $VARS['uid']])[0]; + exit(json_encode(["status" => "OK", "data" => $data])); + } else { + exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + } } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + header("HTTP/1.1 400 Bad Request"); + die("\"400 Bad Request\""); } break; case "userexists":