diff --git a/gatherling/api.php b/gatherling/api.php index 27d107c2e..46bce18e8 100644 --- a/gatherling/api.php +++ b/gatherling/api.php @@ -157,10 +157,10 @@ break; case 'whoami': - auth(); + $auth_error = auth(); $player = Player::getSessionPlayer(); if (is_null($player)) { - error('Not Logged in', ['name' => null]); + error('Not Logged in', ['name' => null, 'auth_error' => $auth_error]); } $result = repr_json_player($player); diff --git a/gatherling/api_lib.php b/gatherling/api_lib.php index b81525c77..559a57316 100644 --- a/gatherling/api_lib.php +++ b/gatherling/api_lib.php @@ -45,7 +45,7 @@ function is_admin() return false; } -/** @return bool */ +/** @return string */ function auth() { $username = null; @@ -60,16 +60,19 @@ function auth() } if (is_null($username) || is_null($apikey)) { - return false; + return "Auth not provided"; } $player = Player::findByName($username); if (is_null($player)) { - return false; + return "Can't find a user called $username"; } if ($player->api_key == $apikey) { $_SESSION['username'] = $player->name; } + else { + return "Invalid API Key"; + } return Player::isLoggedIn(); }