2020-06-13 20:42:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require 'main.php';
|
|
|
|
|
|
|
|
if (!empty($_ENV['DEV'])) {
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
|
|
|
|
ini_set('display_errors', '1');
|
|
|
|
} else {
|
|
|
|
ini_set('display_errors', '0');
|
|
|
|
}
|
|
|
|
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$routeCollection = new SokoWeb\Routing\RouteCollection();
|
2020-06-13 20:42:07 +02:00
|
|
|
|
2020-06-23 20:41:28 +02:00
|
|
|
Container::$routeCollection->get('index', '', [MapGuesser\Controller\MapsController::class, 'getMaps']);
|
2020-06-25 14:01:17 +02:00
|
|
|
Container::$routeCollection->get('startSession', 'startSession.json', [MapGuesser\Controller\HomeController::class, 'startSession']);
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$routeCollection->group('login', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
2020-06-21 15:43:49 +02:00
|
|
|
$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']);
|
|
|
|
});
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$routeCollection->group('signup', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
2020-06-21 15:43:49 +02:00
|
|
|
$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']);
|
|
|
|
$routeCollection->post('signup-google-action', 'google', [MapGuesser\Controller\LoginController::class, 'signupWithGoogle']);
|
|
|
|
$routeCollection->post('signup.reset', 'reset', [MapGuesser\Controller\LoginController::class, 'resetSignup']);
|
|
|
|
$routeCollection->post('signup-google.reset', 'google/reset', [MapGuesser\Controller\LoginController::class, 'resetGoogleSignup']);
|
|
|
|
$routeCollection->get('signup.success', 'success', [MapGuesser\Controller\LoginController::class, 'getSignupSuccess']);
|
|
|
|
$routeCollection->get('signup.activate', 'activate/{token}', [MapGuesser\Controller\LoginController::class, 'activate']);
|
|
|
|
$routeCollection->get('signup.cancel', 'cancel/{token}', [MapGuesser\Controller\LoginController::class, 'cancel']);
|
|
|
|
});
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$routeCollection->group('password', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
2020-07-05 00:09:02 +02:00
|
|
|
$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']);
|
|
|
|
$routeCollection->get('password-reset', 'reset/{token}', [MapGuesser\Controller\LoginController::class, 'getResetPasswordForm']);
|
|
|
|
$routeCollection->post('password-reset.action', 'reset/{token}', [MapGuesser\Controller\LoginController::class, 'resetPassword']);
|
|
|
|
});
|
2020-06-13 20:42:07 +02:00
|
|
|
Container::$routeCollection->get('logout', 'logout', [MapGuesser\Controller\LoginController::class, 'logout']);
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$routeCollection->group('account', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
2020-06-25 16:44:34 +02:00
|
|
|
$routeCollection->get('account', '', [MapGuesser\Controller\UserController::class, 'getAccount']);
|
|
|
|
$routeCollection->post('account-action', '', [MapGuesser\Controller\UserController::class, 'saveAccount']);
|
2020-06-25 20:26:33 +02:00
|
|
|
$routeCollection->get('account.delete', 'delete', [MapGuesser\Controller\UserController::class, 'getDeleteAccount']);
|
|
|
|
$routeCollection->post('account.delete-action', 'delete', [MapGuesser\Controller\UserController::class, 'deleteAccount']);
|
2020-06-28 03:18:51 +02:00
|
|
|
$routeCollection->get('account.googleAuthenticate', 'googleAuthenticate', [MapGuesser\Controller\UserController::class, 'getGoogleAuthenticateRedirect']);
|
|
|
|
$routeCollection->get('account.googleAuthenticate-action', 'googleAuthenticate/code', [MapGuesser\Controller\UserController::class, 'authenticateWithGoogle']);
|
2020-06-21 15:43:49 +02:00
|
|
|
});
|
2020-06-23 20:41:28 +02:00
|
|
|
//Container::$routeCollection->get('maps', 'maps', [MapGuesser\Controller\MapsController::class, 'getMaps']);
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$routeCollection->group('game', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
2020-06-13 20:42:07 +02:00
|
|
|
$routeCollection->get('game', '{mapId}', [MapGuesser\Controller\GameController::class, 'getGame']);
|
2021-03-19 23:00:10 +01:00
|
|
|
$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']);
|
|
|
|
});
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$routeCollection->group('multiGame', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
2021-03-19 23:00:10 +01:00
|
|
|
$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']);
|
|
|
|
$routeCollection->post('multiGame.initialData-json', '{roomId}/initialData.json', [MapGuesser\Controller\GameFlowController::class, 'multiInitialData']);
|
|
|
|
$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']);
|
2020-06-13 20:42:07 +02:00
|
|
|
});
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$routeCollection->group('challenge', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
2021-05-12 13:51:06 +02:00
|
|
|
$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']);
|
|
|
|
});
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$routeCollection->group('admin', function (SokoWeb\Routing\RouteCollection $routeCollection) {
|
2020-06-13 20:42:07 +02:00
|
|
|
$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']);
|
2020-06-14 02:36:23 +02:00
|
|
|
$routeCollection->post('admin.deleteMap', 'deleteMap/{mapId}', [MapGuesser\Controller\MapAdminController::class, 'deleteMap']);
|
2020-06-13 20:42:07 +02:00
|
|
|
});
|
|
|
|
|
2020-06-24 21:37:58 +02:00
|
|
|
if (isset($_COOKIE['COOKIES_CONSENT'])) {
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$sessionHandler = new SokoWeb\Session\DatabaseSessionHandler();
|
2020-06-13 20:42:07 +02:00
|
|
|
|
2020-06-24 21:37:58 +02:00
|
|
|
session_set_save_handler(Container::$sessionHandler, true);
|
|
|
|
session_start([
|
2020-07-05 16:48:37 +02:00
|
|
|
'gc_probability' => 0, // old sessions are deleted by MaintainDatabaseCommand
|
2021-05-09 15:49:27 +02:00
|
|
|
'cookie_lifetime' => 604800,
|
|
|
|
'cookie_path' => '/',
|
2020-06-24 21:37:58 +02:00
|
|
|
'cookie_httponly' => true,
|
|
|
|
'cookie_samesite' => 'Lax'
|
|
|
|
]);
|
2020-07-05 12:25:25 +02:00
|
|
|
|
2021-05-09 15:49:27 +02:00
|
|
|
if (isset($_COOKIE[session_name()])) {
|
|
|
|
// extend session cookie lifetime is cookie already exists
|
|
|
|
setcookie(session_name(), session_id(), [
|
|
|
|
'expires' => time() + 604800,
|
|
|
|
'path' => '/',
|
|
|
|
'httponly' => true,
|
|
|
|
'samesite' => 'Lax'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-07-05 12:25:25 +02:00
|
|
|
// this is needed to handle old type of session IDs
|
|
|
|
if (!Container::$sessionHandler->validateId(session_id())) {
|
|
|
|
session_regenerate_id(true);
|
|
|
|
}
|
2020-06-24 21:37:58 +02:00
|
|
|
} else {
|
|
|
|
$_SESSION = [];
|
|
|
|
}
|
2020-06-13 22:38:30 +02:00
|
|
|
|
2023-04-07 20:01:54 +02:00
|
|
|
Container::$request = new SokoWeb\Request\Request(
|
|
|
|
$_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'],
|
|
|
|
$_GET,
|
|
|
|
$_POST,
|
|
|
|
$_SESSION,
|
|
|
|
new MapGuesser\Repository\UserRepository()
|
|
|
|
);
|
2020-06-14 17:11:48 +02:00
|
|
|
|
|
|
|
if (!Container::$request->session()->has('anti_csrf_token')) {
|
2020-07-05 12:25:25 +02:00
|
|
|
Container::$request->session()->set('anti_csrf_token', bin2hex(random_bytes(16)));
|
2020-06-13 22:38:30 +02:00
|
|
|
}
|