Skip to content

Commit

Permalink
Include auth error when auth fails on whoami
Browse files Browse the repository at this point in the history
  • Loading branch information
silasary committed Jan 27, 2024
1 parent 1287f8d commit 64f8144
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions gatherling/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions gatherling/api_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function is_admin()
return false;
}

/** @return bool */
/** @return string */
function auth()
{
$username = null;
Expand All @@ -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();
}
Expand Down

0 comments on commit 64f8144

Please sign in to comment.