diff --git a/src/Controller/GameController.php b/src/Controller/GameController.php index 55caf22..db6b35c 100644 --- a/src/Controller/GameController.php +++ b/src/Controller/GameController.php @@ -2,7 +2,7 @@ use DateTime; use Faker\Factory; -use SokoWeb\Interfaces\Authorization\ISecured; +use SokoWeb\Interfaces\Authentication\IAuthenticationRequired; use SokoWeb\Interfaces\Request\IRequest; use SokoWeb\Response\HtmlContent; use SokoWeb\Response\JsonContent; @@ -21,7 +21,7 @@ use MapGuesser\Repository\PlaceRepository; use MapGuesser\Repository\UserInChallengeRepository; use SokoWeb\Response\Redirect; -class GameController implements ISecured +class GameController implements IAuthenticationRequired { const NUMBER_OF_ROUNDS = 5; @@ -53,9 +53,9 @@ class GameController implements ISecured $this->userInChallengeRepository = new UserInChallengeRepository(); } - public function authorize(): bool + public function isAuthenticationRequired(): bool { - return !empty($_ENV['ENABLE_GAME_FOR_GUESTS']) || $this->request->user() !== null; + return empty($_ENV['ENABLE_GAME_FOR_GUESTS']); } public function getGame(): IContent diff --git a/src/Controller/GameFlowController.php b/src/Controller/GameFlowController.php index 9ef5cb2..da076a8 100644 --- a/src/Controller/GameFlowController.php +++ b/src/Controller/GameFlowController.php @@ -1,7 +1,7 @@ guessRepository = new GuessRepository(); } - public function authorize(): bool + public function isAuthenticationRequired(): bool { - return !empty($_ENV['ENABLE_GAME_FOR_GUESTS']) || $this->request->user() !== null; + return empty($_ENV['ENABLE_GAME_FOR_GUESTS']); } public function initialData(): IContent diff --git a/src/Controller/MapAdminController.php b/src/Controller/MapAdminController.php index 8d5656e..47a972f 100644 --- a/src/Controller/MapAdminController.php +++ b/src/Controller/MapAdminController.php @@ -2,6 +2,7 @@ use DateTime; use SokoWeb\Interfaces\Authentication\IUser; +use SokoWeb\Interfaces\Authentication\IAuthenticationRequired; use SokoWeb\Interfaces\Authorization\ISecured; use SokoWeb\Interfaces\Request\IRequest; use SokoWeb\Interfaces\Response\IContent; @@ -22,7 +23,7 @@ use SokoWeb\Response\JsonContent; use MapGuesser\Util\Geo\Bounds; use MapGuesser\Util\Panorama\Pov; -class MapAdminController implements ISecured +class MapAdminController implements IAuthenticationRequired, ISecured { private static string $unnamedMapName = '[unnamed map]'; @@ -57,11 +58,14 @@ class MapAdminController implements ISecured $this->userInChallengeRepository = new UserInChallengeRepository(); } + public function isAuthenticationRequired(): bool + { + return true; + } + public function authorize(): bool { - $user = $this->request->user(); - - return $user !== null && $user->hasPermission(IUser::PERMISSION_ADMIN); + return $this->request->user()->hasPermission(IUser::PERMISSION_ADMIN); } public function getMapEditor(): IContent diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 9a7cdb6..4988797 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -2,7 +2,7 @@ use DateTime; use SokoWeb\Http\Request; -use SokoWeb\Interfaces\Authorization\ISecured; +use SokoWeb\Interfaces\Authentication\IAuthenticationRequired; use SokoWeb\Interfaces\Request\IRequest; use SokoWeb\Interfaces\Response\IContent; use SokoWeb\Interfaces\Response\IRedirect; @@ -19,7 +19,7 @@ use SokoWeb\Response\JsonContent; use SokoWeb\Response\Redirect; use SokoWeb\Util\JwtParser; -class UserController implements ISecured +class UserController implements IAuthenticationRequired { private IRequest $request; @@ -46,11 +46,9 @@ class UserController implements ISecured $this->guessRepository = new GuessRepository(); } - public function authorize(): bool + public function isAuthenticationRequired(): bool { - $user = $this->request->user(); - - return $user !== null; + return true; } public function getAccount(): IContent