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