diff --git a/public/index.php b/public/index.php index 81dfb54..14996a8 100644 --- a/public/index.php +++ b/public/index.php @@ -1,66 +1,3 @@ match($method, $url == '' ? [] : explode('/', $url)); - -if ($match !== null) { - list($route, $params) = $match; - - Container::$request->setParsedRouteParams($params); - - $handler = $route->getHandler(); - $controller = new $handler[0](Container::$request); - - if ( - $controller instanceof IAuthenticationRequired && - $controller->isAuthenticationRequired() && - Container::$request->user() === null - ) { - Container::$request->session()->set('redirect_after_login', substr($_SERVER['REQUEST_URI'], strlen('/'))); - $response = new Redirect(Container::$routeCollection->getRoute('login')->generateLink(), IRedirect::TEMPORARY); - header('Location: ' . $response->getUrl(), true, $response->getHttpCode()); - return; - } - - if ($method === 'post' && !in_array($url, $antiCsrfTokenExceptions) && Container::$request->post('anti_csrf_token') !== Container::$request->session()->get('anti_csrf_token')) { - $content = new JsonContent(['error' => 'no_valid_anti_csrf_token']); - header('Content-Type: text/html; charset=UTF-8', true, 403); - $content->render(); - return; - } - - if ( - !($controller instanceof ISecured) || - $controller->authorize() - ) { - $response = call_user_func([$controller, $handler[1]]); - if ($response instanceof IContent) { - header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8'); - $response->render(); - return; - } elseif ($response instanceof IRedirect) { - header('Location: ' . $response->getUrl(), true, $response->getHttpCode()); - return; - } - } -} - -$content = new HtmlContent('error/404'); -header('Content-Type: text/html; charset=UTF-8', true, 404); -$content->render(); diff --git a/src/Controller/CommunityController.php b/src/Controller/CommunityController.php index 30b6e11..b7a6d0f 100644 --- a/src/Controller/CommunityController.php +++ b/src/Controller/CommunityController.php @@ -186,7 +186,7 @@ class CommunityController implements IAuthenticationRequired } return new JsonContent([ - 'redirect' => ['target' => '/' . \Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()])] + 'redirect' => ['target' => \Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()])] ]); } diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php index 346822e..a723817 100644 --- a/src/Controller/LoginController.php +++ b/src/Controller/LoginController.php @@ -47,7 +47,7 @@ class LoginController return new Redirect($this->redirectUrl, IRedirect::TEMPORARY); } - return new HtmlContent('login/login', ['redirectUrl' => '/' . $this->redirectUrl]); + return new HtmlContent('login/login', ['redirectUrl' => $this->redirectUrl]); } public function getGoogleLoginRedirect(): IRedirect @@ -61,7 +61,7 @@ class LoginController $oAuth = new GoogleOAuth(new Request()); $url = $oAuth->getDialogUrl( $state, - $this->request->getBase() . '/' . \Container::$routeCollection->getRoute('login-google-action')->generateLink(), + $this->request->getBase() . \Container::$routeCollection->getRoute('login-google-action')->generateLink(), $nonce ); @@ -99,7 +99,7 @@ class LoginController $user = $this->userRepository->getById($resetter->getUserId()); - return new HtmlContent('login/reset_password', ['success' => true, 'token' => $token, 'email' => $user->getEmail(), 'redirectUrl' => '/' . $this->redirectUrl]); + return new HtmlContent('login/reset_password', ['success' => true, 'token' => $token, 'email' => $user->getEmail(), 'redirectUrl' => $this->redirectUrl]); } public function login(): IContent @@ -141,7 +141,7 @@ class LoginController $oAuth = new GoogleOAuth(new Request()); $tokenData = $oAuth->getToken( $this->request->query('code'), - $this->request->getBase() . '/' . \Container::$routeCollection->getRoute('login-google-action')->generateLink() + $this->request->getBase() . \Container::$routeCollection->getRoute('login-google-action')->generateLink() ); if (!isset($tokenData['id_token'])) { @@ -183,7 +183,7 @@ class LoginController $this->deleteRedirectUrl(); return new JsonContent([ 'redirect' => [ - 'target' => '/' . $this->redirectUrl + 'target' => $this->redirectUrl ] ]); } @@ -247,7 +247,7 @@ class LoginController $this->deleteRedirectUrl(); return new JsonContent([ 'redirect' => [ - 'target' => '/' . $this->redirectUrl + 'target' => $this->redirectUrl ] ]); } @@ -258,7 +258,7 @@ class LoginController if ($resetter === null || $resetter->getExpiresDate() < new DateTime()) { return new JsonContent([ 'redirect' => [ - 'target' => '/' . \Container::$routeCollection->getRoute('password-reset')->generateLink(['token' => $token]) + 'target' => \Container::$routeCollection->getRoute('password-reset')->generateLink(['token' => $token]) ] ]); } @@ -299,7 +299,7 @@ class LoginController $mail->setSubject($_ENV['APP_NAME'] . ' - Password reset'); $mail->setBodyFromTemplate('password-reset', [ 'EMAIL' => $email, - 'RESET_LINK' => $this->request->getBase() . '/' . + 'RESET_LINK' => $this->request->getBase() . \Container::$routeCollection->getRoute('password-reset')->generateLink(['token' => $token]), 'EXPIRES' => $expires->format('Y-m-d H:i T') ]); diff --git a/src/Controller/OAuthController.php b/src/Controller/OAuthController.php index 0666fe7..9c26391 100644 --- a/src/Controller/OAuthController.php +++ b/src/Controller/OAuthController.php @@ -108,10 +108,10 @@ class OAuthController { return new JsonContent([ 'issuer' => $_ENV['APP_URL'], - 'authorization_endpoint' => $this->request->getBase() . '/' . \Container::$routeCollection->getRoute('oauth-auth')->generateLink(), - 'token_endpoint' => $this->request->getBase() . '/' . \Container::$routeCollection->getRoute('oauth-token')->generateLink(), - 'userinfo_endpoint' => $this->request->getBase() . '/' . \Container::$routeCollection->getRoute('oauth-userinfo')->generateLink(), - 'jwks_uri' => $this->request->getBase() . '/' . \Container::$routeCollection->getRoute('oauth-certs')->generateLink(), + 'authorization_endpoint' => $this->request->getBase() . \Container::$routeCollection->getRoute('oauth-auth')->generateLink(), + 'token_endpoint' => $this->request->getBase() . \Container::$routeCollection->getRoute('oauth-token')->generateLink(), + 'userinfo_endpoint' => $this->request->getBase() . \Container::$routeCollection->getRoute('oauth-userinfo')->generateLink(), + 'jwks_uri' => $this->request->getBase() . \Container::$routeCollection->getRoute('oauth-certs')->generateLink(), 'response_types_supported' => [ 'code', diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 43605b2..89edd12 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -62,7 +62,7 @@ class UserController implements IAuthenticationRequired $url = $oAuth->getDialogUrl( $state, - $this->request->getBase() . '/' . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink(), + $this->request->getBase() . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink(), $nonce, $user->getEmail() ); @@ -84,7 +84,7 @@ class UserController implements IAuthenticationRequired $oAuth = new GoogleOAuth(new Request()); $tokenData = $oAuth->getToken( $this->request->query('code'), - $this->request->getBase() . '/' . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink() + $this->request->getBase() . \Container::$routeCollection->getRoute('account.googleAuthenticate-action')->generateLink() ); if (!isset($tokenData['id_token'])) { diff --git a/views/account/account.php b/views/account/account.php index 27e6dcc..f414387 100644 --- a/views/account/account.php +++ b/views/account/account.php @@ -5,7 +5,7 @@ @section(main)