diff --git a/composer.json b/composer.json index 9575416..cf8a1b3 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "esoko/soko-web": "0.3", + "esoko/soko-web": "0.4", "firebase/php-jwt": "^6.4" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 5701037..bd27b77 100644 --- a/composer.lock +++ b/composer.lock @@ -4,15 +4,15 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "64c21f0e5181bd39d8977af72e2aeddc", + "content-hash": "f7786e07bcb0373560ae67549fa28f0b", "packages": [ { "name": "esoko/soko-web", - "version": "v0.3", + "version": "v0.4", "source": { "type": "git", "url": "https://git.esoko.eu/esoko/soko-web.git", - "reference": "014a5480967c03c00dda5ee34c7eaf4be224b96e" + "reference": "948b36c80d324e07339a543d97b9e629487f3a45" }, "require": { "phpmailer/phpmailer": "^6.8", @@ -33,7 +33,7 @@ "GNU GPL 3.0" ], "description": "Lightweight web framework", - "time": "2023-04-16T14:54:22+00:00" + "time": "2023-04-16T18:52:06+00:00" }, { "name": "firebase/php-jwt", 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)