From 54bc9c31db44eefec2824f0dfd3f3a864b1d5583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Mon, 10 May 2021 19:10:09 +0200 Subject: [PATCH] MAPG-143 make it possible to disable game for guests (default is disable) --- .env.example | 1 + src/Controller/GameController.php | 8 +++++++- src/Controller/GameFlowController.php | 8 +++++++- views/maps.php | 14 +++++++++----- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 841b410..82e1f6f 100644 --- a/.env.example +++ b/.env.example @@ -20,3 +20,4 @@ MULTI_INTERNAL_HOST=multi MULTI_INTERNAL_PORT=5000 MULTI_WS_URL=mapguesser-dev.ch:8090 MULTI_WS_PORT=8090 +ENABLE_GAME_FOR_GUESTS=0 diff --git a/src/Controller/GameController.php b/src/Controller/GameController.php index a487644..de9c832 100644 --- a/src/Controller/GameController.php +++ b/src/Controller/GameController.php @@ -2,6 +2,7 @@ use DateTime; use Faker\Factory; +use MapGuesser\Interfaces\Authorization\ISecured; use MapGuesser\Interfaces\Request\IRequest; use MapGuesser\Response\HtmlContent; use MapGuesser\Response\JsonContent; @@ -14,7 +15,7 @@ use MapGuesser\Repository\MapRepository; use MapGuesser\Repository\MultiRoomRepository; use MapGuesser\Response\Redirect; -class GameController +class GameController implements ISecured { private IRequest $request; @@ -35,6 +36,11 @@ class GameController $this->mapRepository = new MapRepository(); } + public function authorize(): bool + { + return !empty($_ENV['ENABLE_GAME_FOR_GUESTS']) || $this->request->user() !== null; + } + public function getGame(): IContent { $mapId = (int) $this->request->query('mapId'); diff --git a/src/Controller/GameFlowController.php b/src/Controller/GameFlowController.php index eba2a48..5dfc4c6 100644 --- a/src/Controller/GameFlowController.php +++ b/src/Controller/GameFlowController.php @@ -1,6 +1,7 @@ userPlayedPlaceRepository = new UserPlayedPlaceRepository(); } + public function authorize(): bool + { + return !empty($_ENV['ENABLE_GAME_FOR_GUESTS']) || $this->request->user() !== null; + } + public function initialData(): IContent { $mapId = (int) $this->request->query('mapId'); diff --git a/views/maps.php b/views/maps.php index 52822ab..2565925 100644 --- a/views/maps.php +++ b/views/maps.php @@ -62,12 +62,16 @@ TODO: condition!
- - - Edit - + user()): ?> + + + Edit + + + + - + Play this map
-- 2.45.2