chore: initialize orderPRO with docs, i18n and scss asset pipeline
This commit is contained in:
46
routes/web.php
Normal file
46
routes/web.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Core\Application;
|
||||
use App\Core\Http\Request;
|
||||
use App\Core\Http\Response;
|
||||
use App\Core\Security\Csrf;
|
||||
use App\Modules\Auth\AuthController;
|
||||
use App\Modules\Auth\AuthMiddleware;
|
||||
|
||||
return static function (Application $app): void {
|
||||
$router = $app->router();
|
||||
$template = $app->template();
|
||||
$auth = $app->auth();
|
||||
$translator = $app->translator();
|
||||
|
||||
$authController = new AuthController($template, $auth, $translator);
|
||||
$authMiddleware = new AuthMiddleware($auth);
|
||||
|
||||
$router->get('/health', static fn (Request $request): Response => Response::json([
|
||||
'status' => 'ok',
|
||||
'app' => (string) $app->config('app.name', 'orderPRO'),
|
||||
'timestamp' => date(DATE_ATOM),
|
||||
]));
|
||||
|
||||
$router->get('/', static function (Request $request) use ($auth): Response {
|
||||
return $auth->check()
|
||||
? Response::redirect('/dashboard')
|
||||
: Response::redirect('/login');
|
||||
});
|
||||
|
||||
$router->get('/login', [$authController, 'showLogin']);
|
||||
$router->post('/login', [$authController, 'login']);
|
||||
$router->post('/logout', [$authController, 'logout'], [$authMiddleware]);
|
||||
|
||||
$router->get('/dashboard', static function (Request $request) use ($template, $auth, $translator): Response {
|
||||
$user = $auth->user();
|
||||
$html = $template->render('dashboard/index', [
|
||||
'title' => $translator->get('dashboard.title'),
|
||||
'user' => $user,
|
||||
'csrfToken' => Csrf::token(),
|
||||
], 'layouts/app');
|
||||
|
||||
return Response::html($html);
|
||||
}, [$authMiddleware]);
|
||||
};
|
||||
Reference in New Issue
Block a user