Pőcze Bence
d666593fde
All checks were successful
mapguesser/pipeline/pr-develop This commit looks good
148 lines
8.0 KiB
PHP
148 lines
8.0 KiB
PHP
<?php
|
|
|
|
use SokoWeb\Response\HttpResponse;
|
|
use SokoWeb\Routing\RouteCollection;
|
|
use SokoWeb\Session\DatabaseSessionHandler;
|
|
use SokoWeb\Request\Request;
|
|
use SokoWeb\Request\Session;
|
|
use MapGuesser\Controller\MapsController;
|
|
use MapGuesser\Controller\HomeController;
|
|
use MapGuesser\Controller\LoginController;
|
|
use MapGuesser\Controller\UserController;
|
|
use MapGuesser\Controller\GameController;
|
|
use MapGuesser\Controller\GameFlowController;
|
|
use MapGuesser\Controller\MapAdminController;
|
|
use MapGuesser\Repository\UserRepository;
|
|
|
|
require 'main.php';
|
|
|
|
if (!empty($_ENV['DEV'])) {
|
|
error_reporting(E_ALL);
|
|
|
|
ini_set('display_errors', '1');
|
|
} else {
|
|
ini_set('display_errors', '0');
|
|
}
|
|
|
|
Container::$routeCollection = new RouteCollection();
|
|
|
|
Container::$routeCollection->get('index', '', [MapsController::class, 'getMaps']);
|
|
Container::$routeCollection->get('startSession', 'startSession.json', [HomeController::class, 'startSession']);
|
|
Container::$routeCollection->group('login', function (RouteCollection $routeCollection) {
|
|
$routeCollection->get('login', '', [LoginController::class, 'getLoginForm']);
|
|
$routeCollection->post('login-action', '', [LoginController::class, 'login']);
|
|
$routeCollection->get('login-google', 'google', [LoginController::class, 'getGoogleLoginRedirect']);
|
|
$routeCollection->get('login-google-action', 'google/code', [LoginController::class, 'loginWithGoogle']);
|
|
});
|
|
Container::$routeCollection->group('signup', function (RouteCollection $routeCollection) {
|
|
$routeCollection->get('signup', '', [LoginController::class, 'getSignupForm']);
|
|
$routeCollection->post('signup-action', '', [LoginController::class, 'signup']);
|
|
$routeCollection->get('signup-google', 'google', [LoginController::class, 'getSignupWithGoogleForm']);
|
|
$routeCollection->post('signup-google-action', 'google', [LoginController::class, 'signupWithGoogle']);
|
|
$routeCollection->post('signup.reset', 'reset', [LoginController::class, 'resetSignup']);
|
|
$routeCollection->post('signup-google.reset', 'google/reset', [LoginController::class, 'resetGoogleSignup']);
|
|
$routeCollection->get('signup.success', 'success', [LoginController::class, 'getSignupSuccess']);
|
|
$routeCollection->get('signup.activate', 'activate/{token}', [LoginController::class, 'activate']);
|
|
$routeCollection->get('signup.cancel', 'cancel/{token}', [LoginController::class, 'cancel']);
|
|
});
|
|
Container::$routeCollection->group('password', function (RouteCollection $routeCollection) {
|
|
$routeCollection->get('password-requestReset', 'requestReset', [LoginController::class, 'getRequestPasswordResetForm']);
|
|
$routeCollection->post('password-requestReset-action', 'requestReset', [LoginController::class, 'requestPasswordReset']);
|
|
$routeCollection->get('password-requestReset.success', 'requestReset/success', [LoginController::class, 'getRequestPasswordResetSuccess']);
|
|
$routeCollection->get('password-reset', 'reset/{token}', [LoginController::class, 'getResetPasswordForm']);
|
|
$routeCollection->post('password-reset.action', 'reset/{token}', [LoginController::class, 'resetPassword']);
|
|
});
|
|
Container::$routeCollection->get('logout', 'logout', [LoginController::class, 'logout']);
|
|
Container::$routeCollection->group('account', function (RouteCollection $routeCollection) {
|
|
$routeCollection->get('account', '', [UserController::class, 'getAccount']);
|
|
$routeCollection->post('account-action', '', [UserController::class, 'saveAccount']);
|
|
$routeCollection->get('account.delete', 'delete', [UserController::class, 'getDeleteAccount']);
|
|
$routeCollection->post('account.delete-action', 'delete', [UserController::class, 'deleteAccount']);
|
|
$routeCollection->get('account.googleAuthenticate', 'googleAuthenticate', [UserController::class, 'getGoogleAuthenticateRedirect']);
|
|
$routeCollection->get('account.googleAuthenticate-action', 'googleAuthenticate/code', [UserController::class, 'authenticateWithGoogle']);
|
|
});
|
|
//Container::$routeCollection->get('maps', 'maps', [MapsController::class, 'getMaps']);
|
|
Container::$routeCollection->group('game', function (RouteCollection $routeCollection) {
|
|
$routeCollection->get('game', '{mapId}', [GameController::class, 'getGame']);
|
|
$routeCollection->post('game.prepare-json', '{mapId}/prepare.json', [GameController::class, 'prepareGame']);
|
|
$routeCollection->post('game.initialData-json', '{mapId}/initialData.json', [GameFlowController::class, 'initialData']);
|
|
$routeCollection->post('game.guess-json', '{mapId}/guess.json', [GameFlowController::class, 'guess']);
|
|
});
|
|
Container::$routeCollection->group('multiGame', function (RouteCollection $routeCollection) {
|
|
$routeCollection->get('multiGame.new', 'new/{mapId}', [GameController::class, 'getNewMultiGame']);
|
|
$routeCollection->get('multiGame', '{roomId}', [GameController::class, 'getMultiGame']);
|
|
$routeCollection->post('multiGame.prepare-json', '{roomId}/prepare.json', [GameController::class, 'prepareMultiGame']);
|
|
$routeCollection->post('multiGame.initialData-json', '{roomId}/initialData.json', [GameFlowController::class, 'multiInitialData']);
|
|
$routeCollection->post('multiGame.nextRound-json', '{roomId}/nextRound.json', [GameFlowController::class, 'multiNextRound']);
|
|
$routeCollection->post('multiGame.guess-json', '{roomId}/guess.json', [GameFlowController::class, 'multiGuess']);
|
|
});
|
|
Container::$routeCollection->group('challenge', function (RouteCollection $routeCollection) {
|
|
$routeCollection->post('challenge.create', 'create.json', [GameController::class, 'createNewChallenge']);
|
|
$routeCollection->get('challenge', '{challengeToken}', [GameController::class, 'getChallenge']);
|
|
$routeCollection->post('challenge.prepare-json', '{challengeToken}/prepare.json', [GameController::class, 'prepareChallenge']);
|
|
$routeCollection->post('challenge.initialData-json', '{challengeToken}/initialData.json', [GameFlowController::class, 'challengeInitialData']);
|
|
$routeCollection->post('challenge.guess-json', '{challengeToken}/guess.json', [GameFlowController::class, 'challengeGuess']);
|
|
});
|
|
Container::$routeCollection->group('admin', function (RouteCollection $routeCollection) {
|
|
$routeCollection->get('admin.mapEditor', 'mapEditor/{mapId?}', [MapAdminController::class, 'getMapEditor']);
|
|
$routeCollection->get('admin.place', 'place.json/{placeId}', [MapAdminController::class, 'getPlace']);
|
|
$routeCollection->post('admin.saveMap', 'saveMap/{mapId}/json', [MapAdminController::class, 'saveMap']);
|
|
$routeCollection->post('admin.deleteMap', 'deleteMap/{mapId}', [MapAdminController::class, 'deleteMap']);
|
|
});
|
|
|
|
if (isset($_COOKIE['COOKIES_CONSENT'])) {
|
|
Container::$sessionHandler = new DatabaseSessionHandler(
|
|
Container::$dbConnection,
|
|
'sessions',
|
|
new DateTime('-7 days')
|
|
);
|
|
|
|
session_set_save_handler(Container::$sessionHandler, true);
|
|
session_start([
|
|
'gc_probability' => 0, // old sessions are deleted by MaintainDatabaseCommand
|
|
'cookie_lifetime' => 0,
|
|
'cookie_path' => '/',
|
|
'cookie_httponly' => true,
|
|
'cookie_samesite' => 'Lax'
|
|
]);
|
|
|
|
// this is needed to handle old type of session IDs
|
|
if (!Container::$sessionHandler->validateId(session_id())) {
|
|
session_regenerate_id(true);
|
|
}
|
|
} else {
|
|
$_SESSION = [];
|
|
}
|
|
|
|
Container::$request = new Request(
|
|
$_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'],
|
|
$_GET,
|
|
$_POST,
|
|
getallheaders(),
|
|
new Session($_SESSION),
|
|
new UserRepository()
|
|
);
|
|
|
|
if (!Container::$request->session()->has('anti_csrf_token')) {
|
|
Container::$request->session()->set('anti_csrf_token', bin2hex(random_bytes(16)));
|
|
}
|
|
|
|
$appConfig = [
|
|
'antiCsrfTokenName' => 'anti_csrf_token',
|
|
'antiCsrfTokenErrorResponse' => ['error' => 'no_valid_anti_csrf_token'],
|
|
'antiCsrfTokenExceptions' => [],
|
|
'loginRouteId' => 'login',
|
|
'error404View' => 'error/404',
|
|
'error500View' => 'error/500'
|
|
];
|
|
|
|
$httpReponse = new HttpResponse(
|
|
Container::$request,
|
|
Container::$dbConnection,
|
|
Container::$routeCollection,
|
|
$appConfig,
|
|
$_SERVER['REQUEST_METHOD'],
|
|
$_SERVER['REQUEST_URI']
|
|
);
|
|
$httpReponse->render();
|