diff --git a/.env.example b/.env.example index ee070c8..3b6ecd4 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ APP_NAME=MapGuesser +APP_URL=mapguesser.dev DEV=1 DB_HOST=mariadb DB_USER=mapguesser diff --git a/database/migrations/data/20200612_2124_map_area.php b/database/migrations/data/20200612_2124_map_area.php index dae5e11..98f35ef 100644 --- a/database/migrations/data/20200612_2124_map_area.php +++ b/database/migrations/data/20200612_2124_map_area.php @@ -1,8 +1,8 @@ columns(['id']); diff --git a/main.php b/main.php index fbf78d9..f3a2309 100644 --- a/main.php +++ b/main.php @@ -14,10 +14,10 @@ $dotenv->load(); class Container { - static MapGuesser\Interfaces\Database\IConnection $dbConnection; - static MapGuesser\Routing\RouteCollection $routeCollection; - static MapGuesser\Interfaces\Session\ISessionHandler $sessionHandler; - static MapGuesser\Interfaces\Request\IRequest $request; + static SokoWeb\Interfaces\Database\IConnection $dbConnection; + static SokoWeb\Routing\RouteCollection $routeCollection; + static SokoWeb\Interfaces\Session\ISessionHandler $sessionHandler; + static SokoWeb\Interfaces\Request\IRequest $request; } -Container::$dbConnection = new MapGuesser\Database\Mysql\Connection($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']); +Container::$dbConnection = new SokoWeb\Database\Mysql\Connection($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']); diff --git a/mapg b/mapg index 65ffefd..503b535 100755 --- a/mapg +++ b/mapg @@ -8,6 +8,6 @@ $app = new Symfony\Component\Console\Application('MapGuesser Console', ''); $app->add(new MapGuesser\Cli\MigrateDatabaseCommand()); $app->add(new MapGuesser\Cli\AddUserCommand()); $app->add(new MapGuesser\Cli\LinkViewCommand()); -$app->add(new \MapGuesser\Cli\MaintainDatabaseCommand()); +$app->add(new MapGuesser\Cli\MaintainDatabaseCommand()); $app->run(); diff --git a/public/index.php b/public/index.php index e58da6f..d48250f 100644 --- a/public/index.php +++ b/public/index.php @@ -19,14 +19,14 @@ if ($match !== null) { $handler = $route->getHandler(); $controller = new $handler[0](Container::$request); - if ($controller instanceof MapGuesser\Interfaces\Authorization\ISecured) { + if ($controller instanceof SokoWeb\Interfaces\Authorization\ISecured) { $authorized = $controller->authorize(); } else { $authorized = true; } if ($method === 'post' && Container::$request->post('anti_csrf_token') !== Container::$request->session()->get('anti_csrf_token')) { - $content = new MapGuesser\Response\JsonContent(['error' => 'no_valid_anti_csrf_token']); + $content = new SokoWeb\Response\JsonContent(['error' => 'no_valid_anti_csrf_token']); header('Content-Type: text/html; charset=UTF-8', true, 403); $content->render(); return; @@ -35,12 +35,12 @@ if ($match !== null) { if ($authorized) { $response = call_user_func([$controller, $handler[1]]); - if ($response instanceof MapGuesser\Interfaces\Response\IContent) { + if ($response instanceof SokoWeb\Interfaces\Response\IContent) { header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8'); $response->render(); return; - } elseif ($response instanceof MapGuesser\Interfaces\Response\IRedirect) { + } elseif ($response instanceof SokoWeb\Interfaces\Response\IRedirect) { header('Location: ' . $response->getUrl(), true, $response->getHttpCode()); return; @@ -48,6 +48,6 @@ if ($match !== null) { } } -$content = new MapGuesser\Response\HtmlContent('error/404'); +$content = new SokoWeb\Response\HtmlContent('error/404'); header('Content-Type: text/html; charset=UTF-8', true, 404); $content->render(); diff --git a/src/Cli/AddUserCommand.php b/src/Cli/AddUserCommand.php index b63a0d2..8e6036f 100644 --- a/src/Cli/AddUserCommand.php +++ b/src/Cli/AddUserCommand.php @@ -1,7 +1,7 @@ request->query('challengeToken'); return new HtmlContent('game', ['challengeToken' => $challengeToken]); @@ -120,7 +120,7 @@ class GameController implements ISecured $challenge = new Challenge(); $challenge->setToken($challengeToken); $challenge->setCreatedDate(new DateTime()); - + if ($this->request->post('timerEnabled') !== null && $this->request->post('timeLimit') !== null) { $challenge->setTimeLimit($this->request->post('timeLimit')); } diff --git a/src/Controller/GameFlowController.php b/src/Controller/GameFlowController.php index 3f4c586..48e4dd2 100644 --- a/src/Controller/GameFlowController.php +++ b/src/Controller/GameFlowController.php @@ -1,13 +1,13 @@ where('token', '=', $token); - + return $this->pdm->selectFromDb($select, Challenge::class); } @@ -72,4 +72,4 @@ class ChallengeRepository yield from $this->pdm->selectMultipleFromDb($select, Challenge::class); } -} \ No newline at end of file +} diff --git a/src/Repository/GuessRepository.php b/src/Repository/GuessRepository.php index 9e54b1b..307429c 100644 --- a/src/Repository/GuessRepository.php +++ b/src/Repository/GuessRepository.php @@ -1,14 +1,13 @@ where('challenge_id', '=', $challenge->getId()); $select->where('round', '=', $round); diff --git a/src/Repository/MapRepository.php b/src/Repository/MapRepository.php index 6b41dc0..d2a1f83 100644 --- a/src/Repository/MapRepository.php +++ b/src/Repository/MapRepository.php @@ -1,10 +1,10 @@ getRandomOldNForMapWithValidPano($mapId, $n - count($unvisitedPlaces), $userId); - + return array_merge($unvisitedPlaces, $oldPlaces); } } @@ -198,5 +198,5 @@ class PlaceRepository yield from $this->pdm->selectMultipleFromDb($select, Place::class); } - + } diff --git a/src/Repository/UserConfirmationRepository.php b/src/Repository/UserConfirmationRepository.php index d7d80ad..3cd80e0 100644 --- a/src/Repository/UserConfirmationRepository.php +++ b/src/Repository/UserConfirmationRepository.php @@ -1,9 +1,9 @@ get('index', '', [MapGuesser\Controller\MapsController::class, 'getMaps']); Container::$routeCollection->get('startSession', 'startSession.json', [MapGuesser\Controller\HomeController::class, 'startSession']); -Container::$routeCollection->group('login', function (MapGuesser\Routing\RouteCollection $routeCollection) { +Container::$routeCollection->group('login', function (SokoWeb\Routing\RouteCollection $routeCollection) { $routeCollection->get('login', '', [MapGuesser\Controller\LoginController::class, 'getLoginForm']); $routeCollection->post('login-action', '', [MapGuesser\Controller\LoginController::class, 'login']); $routeCollection->get('login-google', 'google', [MapGuesser\Controller\LoginController::class, 'getGoogleLoginRedirect']); $routeCollection->get('login-google-action', 'google/code', [MapGuesser\Controller\LoginController::class, 'loginWithGoogle']); }); -Container::$routeCollection->group('signup', function (MapGuesser\Routing\RouteCollection $routeCollection) { +Container::$routeCollection->group('signup', function (SokoWeb\Routing\RouteCollection $routeCollection) { $routeCollection->get('signup', '', [MapGuesser\Controller\LoginController::class, 'getSignupForm']); $routeCollection->post('signup-action', '', [MapGuesser\Controller\LoginController::class, 'signup']); $routeCollection->get('signup-google', 'google', [MapGuesser\Controller\LoginController::class, 'getSignupWithGoogleForm']); @@ -31,7 +31,7 @@ Container::$routeCollection->group('signup', function (MapGuesser\Routing\RouteC $routeCollection->get('signup.activate', 'activate/{token}', [MapGuesser\Controller\LoginController::class, 'activate']); $routeCollection->get('signup.cancel', 'cancel/{token}', [MapGuesser\Controller\LoginController::class, 'cancel']); }); -Container::$routeCollection->group('password', function (MapGuesser\Routing\RouteCollection $routeCollection) { +Container::$routeCollection->group('password', function (SokoWeb\Routing\RouteCollection $routeCollection) { $routeCollection->get('password-requestReset', 'requestReset', [MapGuesser\Controller\LoginController::class, 'getRequestPasswordResetForm']); $routeCollection->post('password-requestReset-action', 'requestReset', [MapGuesser\Controller\LoginController::class, 'requestPasswordReset']); $routeCollection->get('password-requestReset.success', 'requestReset/success', [MapGuesser\Controller\LoginController::class, 'getRequestPasswordResetSuccess']); @@ -39,7 +39,7 @@ Container::$routeCollection->group('password', function (MapGuesser\Routing\Rout $routeCollection->post('password-reset.action', 'reset/{token}', [MapGuesser\Controller\LoginController::class, 'resetPassword']); }); Container::$routeCollection->get('logout', 'logout', [MapGuesser\Controller\LoginController::class, 'logout']); -Container::$routeCollection->group('account', function (MapGuesser\Routing\RouteCollection $routeCollection) { +Container::$routeCollection->group('account', function (SokoWeb\Routing\RouteCollection $routeCollection) { $routeCollection->get('account', '', [MapGuesser\Controller\UserController::class, 'getAccount']); $routeCollection->post('account-action', '', [MapGuesser\Controller\UserController::class, 'saveAccount']); $routeCollection->get('account.delete', 'delete', [MapGuesser\Controller\UserController::class, 'getDeleteAccount']); @@ -48,13 +48,13 @@ Container::$routeCollection->group('account', function (MapGuesser\Routing\Route $routeCollection->get('account.googleAuthenticate-action', 'googleAuthenticate/code', [MapGuesser\Controller\UserController::class, 'authenticateWithGoogle']); }); //Container::$routeCollection->get('maps', 'maps', [MapGuesser\Controller\MapsController::class, 'getMaps']); -Container::$routeCollection->group('game', function (MapGuesser\Routing\RouteCollection $routeCollection) { +Container::$routeCollection->group('game', function (SokoWeb\Routing\RouteCollection $routeCollection) { $routeCollection->get('game', '{mapId}', [MapGuesser\Controller\GameController::class, 'getGame']); $routeCollection->post('game.prepare-json', '{mapId}/prepare.json', [MapGuesser\Controller\GameController::class, 'prepareGame']); $routeCollection->post('game.initialData-json', '{mapId}/initialData.json', [MapGuesser\Controller\GameFlowController::class, 'initialData']); $routeCollection->post('game.guess-json', '{mapId}/guess.json', [MapGuesser\Controller\GameFlowController::class, 'guess']); }); -Container::$routeCollection->group('multiGame', function (MapGuesser\Routing\RouteCollection $routeCollection) { +Container::$routeCollection->group('multiGame', function (SokoWeb\Routing\RouteCollection $routeCollection) { $routeCollection->get('multiGame.new', 'new/{mapId}', [MapGuesser\Controller\GameController::class, 'getNewMultiGame']); $routeCollection->get('multiGame', '{roomId}', [MapGuesser\Controller\GameController::class, 'getMultiGame']); $routeCollection->post('multiGame.prepare-json', '{roomId}/prepare.json', [MapGuesser\Controller\GameController::class, 'prepareMultiGame']); @@ -62,14 +62,14 @@ Container::$routeCollection->group('multiGame', function (MapGuesser\Routing\Rou $routeCollection->post('multiGame.nextRound-json', '{roomId}/nextRound.json', [MapGuesser\Controller\GameFlowController::class, 'multiNextRound']); $routeCollection->post('multiGame.guess-json', '{roomId}/guess.json', [MapGuesser\Controller\GameFlowController::class, 'multiGuess']); }); -Container::$routeCollection->group('challenge', function (MapGuesser\Routing\RouteCollection $routeCollection) { +Container::$routeCollection->group('challenge', function (SokoWeb\Routing\RouteCollection $routeCollection) { $routeCollection->post('challenge.create', 'create.json', [\MapGuesser\Controller\GameController::class, 'createNewChallenge']); $routeCollection->get('challenge', '{challengeToken}', [MapGuesser\Controller\GameController::class, 'getChallenge']); $routeCollection->post('challenge.prepare-json', '{challengeToken}/prepare.json', [MapGuesser\Controller\GameController::class, 'prepareChallenge']); $routeCollection->post('challenge.initialData-json', '{challengeToken}/initialData.json', [MapGuesser\Controller\GameFlowController::class, 'challengeInitialData']); $routeCollection->post('challenge.guess-json', '{challengeToken}/guess.json', [MapGuesser\Controller\GameFlowController::class, 'challengeGuess']); }); -Container::$routeCollection->group('admin', function (MapGuesser\Routing\RouteCollection $routeCollection) { +Container::$routeCollection->group('admin', function (SokoWeb\Routing\RouteCollection $routeCollection) { $routeCollection->get('admin.mapEditor', 'mapEditor/{mapId?}', [MapGuesser\Controller\MapAdminController::class, 'getMapEditor']); $routeCollection->get('admin.place', 'place.json/{placeId}', [MapGuesser\Controller\MapAdminController::class, 'getPlace']); $routeCollection->post('admin.saveMap', 'saveMap/{mapId}/json', [MapGuesser\Controller\MapAdminController::class, 'saveMap']); @@ -77,7 +77,7 @@ Container::$routeCollection->group('admin', function (MapGuesser\Routing\RouteCo }); if (isset($_COOKIE['COOKIES_CONSENT'])) { - Container::$sessionHandler = new MapGuesser\Session\DatabaseSessionHandler(); + Container::$sessionHandler = new SokoWeb\Session\DatabaseSessionHandler(); session_set_save_handler(Container::$sessionHandler, true); session_start([ @@ -106,7 +106,13 @@ if (isset($_COOKIE['COOKIES_CONSENT'])) { $_SESSION = []; } -Container::$request = new MapGuesser\Request\Request($_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'], $_GET, $_POST, $_SESSION); +Container::$request = new SokoWeb\Request\Request( + $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'], + $_GET, + $_POST, + $_SESSION, + new MapGuesser\Repository\UserRepository() +); if (!Container::$request->session()->has('anti_csrf_token')) { Container::$request->session()->set('anti_csrf_token', bin2hex(random_bytes(16)));