Skip to content

Commit

Permalink
Use Basic Auth instead of custom headers
Browse files Browse the repository at this point in the history
  • Loading branch information
silasary committed Jan 27, 2024
1 parent a7db61a commit bc95323
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gatherling/api_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ function is_admin()
/** @return bool */
function auth()
{
if (isset($_SERVER['HTTP_X_USERNAME']) && isset($_SERVER['HTTP_X_APIKEY'])) {
$username = $_SERVER['HTTP_X_USERNAME'];
$apikey = $_SERVER['HTTP_X_APIKEY'];
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
$username = $_SERVER['PHP_AUTH_USER'];
$apikey = $_SERVER['PHP_AUTH_PW'];
if (is_null($username) || is_null($apikey)) {
return false;
}
Expand Down Expand Up @@ -246,6 +246,7 @@ function repr_json_player($player, $client = null)
*/
function add_player_to_event($event, $name, $decklist)
{
$result = [];
if ($event->authCheck($_SESSION['username'])) {
if ($event->addPlayer($name)) {
$player = new Player($name);
Expand All @@ -267,7 +268,7 @@ function add_player_to_event($event, $name, $decklist)
$deck->sideboard_cards = parseCardsWithQuantity('');
$deck->save();

return $deck;
$result['deck'] = repr_json_deck($deck);
}
} else {
$result['error'] = 'Unauthorized';
Expand Down

0 comments on commit bc95323

Please sign in to comment.