From a5823b3e0e2fbbfaf0cf2606df149e5af025b085 Mon Sep 17 00:00:00 2001 From: Vari Date: Wed, 6 Mar 2024 18:22:22 +0100 Subject: [PATCH] Fixed some bugs with the validation of the end of match requests. Forgot to change the false of the Authorize() method. Fixed comparison of Match creator and user that send teh request. To compare objects don't use ===, use == instead. --- .../Controllers/Api/Matchmaking/MatchmakingController.php | 6 +++--- .../Http/Controllers/Api/Player/ChallengeController.php | 2 +- .../Http/Requests/Api/Matchmaking/EndOfMatchRequest.php | 7 ++++--- .../Requests/Api/Matchmaking/PlayerEndOfMatchRequest.php | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php b/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php index 7899043..573664d 100644 --- a/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php +++ b/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php @@ -114,8 +114,8 @@ public function endOfMatch(EndOfMatchRequest $request) $game = Game::find($request->matchId); $user = Auth::user(); - if($game->creator !== $user) - throw new AuthorizationException('you are not the creator of the match.'); + if($game->creator != $user) + return response('you are not the creator of the match.', 403); $game->status = MatchStatus::Killed; $game->save(); @@ -131,7 +131,7 @@ public function playerEndOfMatch(PlayerEndOfMatchRequest $request) if($game === null) return response('Match not found.', 404); - if ($game->creator !== $user) + if ($game->creator != $user) throw new AuthorizationException('User is not host of given match'); $user = User::find($request->playerId); diff --git a/dist/app/Http/Controllers/Api/Player/ChallengeController.php b/dist/app/Http/Controllers/Api/Player/ChallengeController.php index c32d067..7d44e38 100644 --- a/dist/app/Http/Controllers/Api/Player/ChallengeController.php +++ b/dist/app/Http/Controllers/Api/Player/ChallengeController.php @@ -76,7 +76,7 @@ public function executeChallengeProgressionBatch(ExecuteChallengeProgressionBatc // Only allow the saving of challenge progress if the request comes from the same user as from the // game the request is coming from. - if($user !== $foundGame->creator) + if($user != $foundGame->creator) throw new AuthorizationException('Not allowed to save progress'); $progressUser = User::find($request->userId); diff --git a/dist/app/Http/Requests/Api/Matchmaking/EndOfMatchRequest.php b/dist/app/Http/Requests/Api/Matchmaking/EndOfMatchRequest.php index 385c1e5..000843a 100644 --- a/dist/app/Http/Requests/Api/Matchmaking/EndOfMatchRequest.php +++ b/dist/app/Http/Requests/Api/Matchmaking/EndOfMatchRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\Api\Matchmaking; use App\Enums\Game\Faction; +use Auth; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; @@ -19,7 +20,7 @@ class EndOfMatchRequest extends FormRequest */ public function authorize(): bool { - return false; + return Auth::check(); } /** @@ -39,7 +40,7 @@ public function rules(): array protected function passedValidation() { $this->players = $this->input('data.players'); - $this->dominantFaction = $this->input('data.dominantFaction'); - $this->matchId = $this->input('matchId'); + $this->dominantFaction = Faction::tryFrom($this->input('data.dominantFaction')); + $this->matchId = $this->input('data.matchId'); } } diff --git a/dist/app/Http/Requests/Api/Matchmaking/PlayerEndOfMatchRequest.php b/dist/app/Http/Requests/Api/Matchmaking/PlayerEndOfMatchRequest.php index 5e311fa..b30ba80 100644 --- a/dist/app/Http/Requests/Api/Matchmaking/PlayerEndOfMatchRequest.php +++ b/dist/app/Http/Requests/Api/Matchmaking/PlayerEndOfMatchRequest.php @@ -5,6 +5,7 @@ use App\Enums\Game\Faction; use App\Enums\Game\ItemGroupType; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Support\Facades\Auth; use Illuminate\Validation\Rule; class PlayerEndOfMatchRequest extends FormRequest @@ -38,7 +39,7 @@ class PlayerEndOfMatchRequest extends FormRequest */ public function authorize(): bool { - return false; + return Auth::check(); } /**