2021-07-05 14:39:51 +02:00
|
|
|
<?php
|
|
|
|
|
2024-10-05 14:44:20 +02:00
|
|
|
use Formwork\App;
|
2024-10-05 20:08:22 +02:00
|
|
|
use Formwork\Config\Config;
|
2023-07-29 22:39:28 +02:00
|
|
|
use Formwork\Http\JsonResponse;
|
|
|
|
use Formwork\Http\RedirectResponse;
|
|
|
|
use Formwork\Http\Request;
|
2024-10-05 20:08:22 +02:00
|
|
|
use Formwork\Http\Response;
|
2023-07-29 22:39:28 +02:00
|
|
|
use Formwork\Http\ResponseStatus;
|
2024-10-25 01:13:00 +02:00
|
|
|
use Formwork\Panel\Controllers\AuthenticationController;
|
2023-07-29 22:39:28 +02:00
|
|
|
use Formwork\Panel\Panel;
|
|
|
|
use Formwork\Security\CsrfToken;
|
2024-10-05 12:41:35 +02:00
|
|
|
use Formwork\Site;
|
2023-07-29 22:39:28 +02:00
|
|
|
use Formwork\Translations\Translations;
|
2022-11-28 23:05:44 +01:00
|
|
|
use Formwork\Utils\FileSystem;
|
2024-10-05 20:08:22 +02:00
|
|
|
use Formwork\View\ViewFactory;
|
2022-11-27 19:30:41 +01:00
|
|
|
|
2021-07-05 14:39:51 +02:00
|
|
|
return [
|
|
|
|
'routes' => [
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.index' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/',
|
2023-07-29 22:39:28 +02:00
|
|
|
'action' => fn (Panel $panel) => new RedirectResponse($panel->uri('/dashboard/')),
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.login' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/login/',
|
2024-04-27 13:08:58 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\AuthenticationController@login',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.logout' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/logout/',
|
2024-04-27 13:08:58 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\AuthenticationController@logout',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.backup.make' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/backup/make/',
|
2024-04-27 13:08:58 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\BackupController@make',
|
2021-07-05 14:39:51 +02:00
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.backup.download' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/backup/download/{backup}/',
|
2024-04-27 13:08:58 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\BackupController@download',
|
2023-12-31 12:33:24 +01:00
|
|
|
'methods' => ['GET', 'POST'],
|
|
|
|
],
|
|
|
|
|
|
|
|
'panel.backup.delete' => [
|
|
|
|
'path' => '/backup/delete/{backup}/',
|
2024-04-27 13:08:58 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\BackupController@delete',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.cache.clear' => [
|
2024-05-14 23:41:44 +02:00
|
|
|
'path' => '/cache/clear/{type}?/',
|
2024-04-27 13:08:58 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\CacheController@clear',
|
2021-07-05 14:39:51 +02:00
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.dashboard' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/dashboard/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\DashboardController@index',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.options' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/options/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\OptionsController@index',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.options.system' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/options/system/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\OptionsController@systemOptions',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.options.site' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/options/site/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\OptionsController@siteOptions',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@index',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2023-12-31 12:33:24 +01:00
|
|
|
'panel.tools' => [
|
|
|
|
'path' => '/tools/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\ToolsController@index',
|
|
|
|
],
|
|
|
|
|
|
|
|
'panel.tools.backups' => [
|
|
|
|
'path' => '/tools/backups/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\ToolsController@backups',
|
|
|
|
],
|
|
|
|
|
|
|
|
'panel.tools.updates' => [
|
|
|
|
'path' => '/tools/updates/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\ToolsController@updates',
|
|
|
|
],
|
|
|
|
|
2024-06-08 22:46:26 +02:00
|
|
|
'panel.tools.info' => [
|
|
|
|
'path' => '/tools/info/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\ToolsController@info',
|
|
|
|
],
|
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.new' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/new/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@create',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.edit' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/edit/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@edit',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2024-09-17 22:07:33 +02:00
|
|
|
'panel.pages.preview' => [
|
|
|
|
'path' => '/pages/{page}/preview/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@preview',
|
|
|
|
'methods' => ['POST'],
|
|
|
|
],
|
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.edit.lang' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/edit/language/{language}/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@edit',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.reorder' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/reorder/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@reorder',
|
2021-07-05 14:39:51 +02:00
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.uploadfile' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/file/upload/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@uploadFile',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.deletefile' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/file/{filename}/delete/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@deleteFile',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2023-07-30 17:32:20 +02:00
|
|
|
'panel.pages.renameFile' => [
|
|
|
|
'path' => '/pages/{page}/file/{filename}/rename/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@renameFile',
|
|
|
|
'methods' => ['POST'],
|
|
|
|
],
|
|
|
|
|
2024-05-12 19:36:30 +02:00
|
|
|
'panel.pages.replaceFile' => [
|
|
|
|
'path' => '/pages/{page}/file/{filename}/replace/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@replaceFile',
|
|
|
|
'methods' => ['POST'],
|
|
|
|
],
|
|
|
|
|
|
|
|
'panel.pages.file' => [
|
|
|
|
'path' => '/pages/{page}/file/{filename}/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@file',
|
2024-10-13 12:42:06 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2024-05-12 19:36:30 +02:00
|
|
|
],
|
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.delete' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/delete/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@delete',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.pages.delete.lang' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/pages/{page}/delete/language/{language}/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\PagesController@delete',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.updates.check' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/updates/check/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UpdatesController@check',
|
2021-07-05 14:39:51 +02:00
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.updates.update' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/updates/update/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UpdatesController@update',
|
2021-07-05 14:39:51 +02:00
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2023-12-29 13:53:31 +01:00
|
|
|
'panel.statistics' => [
|
|
|
|
'path' => '/statistics/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\StatisticsController@index',
|
|
|
|
],
|
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.users' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/users/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UsersController@index',
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.users.new' => [
|
2021-07-05 14:39:51 +02:00
|
|
|
'path' => '/users/new/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UsersController@create',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.users.delete' => [
|
2024-10-06 14:35:55 +02:00
|
|
|
'path' => '/users/{user:[a-z0-9_-]+}/delete/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UsersController@delete',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2024-10-06 14:35:55 +02:00
|
|
|
'panel.users.deleteImage' => [
|
|
|
|
'path' => '/users/{user:[a-z0-9_-]+}/image/delete/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\UsersController@deleteImage',
|
|
|
|
'methods' => ['POST'],
|
|
|
|
],
|
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.users.profile' => [
|
2024-10-06 14:35:55 +02:00
|
|
|
'path' => '/users/{user:[a-z0-9_-]+}/profile/',
|
2022-11-27 21:21:19 +01:00
|
|
|
'action' => 'Formwork\Panel\Controllers\UsersController@profile',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2022-11-23 22:50:16 +01:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2024-10-04 15:24:53 +02:00
|
|
|
'panel.users.images' => [
|
|
|
|
'path' => '/users/images/{image}/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\UsersController@images',
|
|
|
|
'methods' => ['GET'],
|
|
|
|
],
|
|
|
|
|
2022-11-28 23:05:44 +01:00
|
|
|
'panel.register' => [
|
|
|
|
'path' => '/register/',
|
|
|
|
'action' => 'Formwork\Panel\Controllers\RegisterController@register',
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2022-11-28 23:05:44 +01:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.errors.notfound' => [
|
2022-12-11 16:48:45 +01:00
|
|
|
'path' => '/{route}/',
|
2023-05-20 21:26:49 +02:00
|
|
|
'action' => 'Formwork\Panel\Controllers\ErrorsController@notFound',
|
|
|
|
],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-12-11 16:48:45 +01:00
|
|
|
|
2021-07-05 14:39:51 +02:00
|
|
|
'filters' => [
|
2024-06-16 14:55:53 +02:00
|
|
|
'panel.request.validateSize' => [
|
2023-07-29 22:39:28 +02:00
|
|
|
'action' => static function (Request $request, Translations $translations, Panel $panel) {
|
2022-11-28 23:05:44 +01:00
|
|
|
// Validate HTTP request Content-Length according to `post_max_size` directive
|
2023-07-29 22:39:28 +02:00
|
|
|
if ($request->contentLength() !== null) {
|
2023-12-28 12:49:13 +01:00
|
|
|
$maxSize = FileSystem::shorthandToBytes(ini_get('post_max_size') ?: '0');
|
2022-11-28 23:05:44 +01:00
|
|
|
|
2023-07-29 22:39:28 +02:00
|
|
|
if ($request->contentLength() > $maxSize && $maxSize > 0) {
|
2022-11-28 23:05:44 +01:00
|
|
|
$panel->notify(
|
2023-07-29 22:39:28 +02:00
|
|
|
$translations->getCurrent()->translate('panel.request.error.postMaxSize'),
|
2022-11-28 23:05:44 +01:00
|
|
|
'error'
|
|
|
|
);
|
|
|
|
return new RedirectResponse($panel->uri());
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['POST'],
|
2024-06-16 14:55:53 +02:00
|
|
|
'types' => ['HTTP', 'XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-11-28 23:05:44 +01:00
|
|
|
|
2024-06-16 14:55:53 +02:00
|
|
|
'panel.request.validateCsrf' => [
|
2023-07-29 22:39:28 +02:00
|
|
|
'action' => static function (Request $request, Translations $translations, Panel $panel, CsrfToken $csrfToken) {
|
2024-06-16 14:55:53 +02:00
|
|
|
$tokenName = $panel->getCsrfTokenName();
|
|
|
|
$token = (string) $request->input()->get('csrf-token');
|
2024-05-15 22:26:17 +02:00
|
|
|
|
2024-06-16 14:55:53 +02:00
|
|
|
if (!$csrfToken->validate($tokenName, $token)) {
|
|
|
|
$csrfToken->destroy($tokenName);
|
2024-10-25 01:13:00 +02:00
|
|
|
$panel->user()->logout();
|
2022-11-28 23:05:44 +01:00
|
|
|
|
|
|
|
$panel->notify(
|
2023-07-29 22:39:28 +02:00
|
|
|
$translations->getCurrent()->translate('panel.login.suspiciousRequestDetected'),
|
2022-11-28 23:05:44 +01:00
|
|
|
'warning'
|
|
|
|
);
|
|
|
|
|
2023-07-29 22:39:28 +02:00
|
|
|
if ($request->isXmlHttpRequest()) {
|
|
|
|
return JsonResponse::error('Bad Request: the CSRF token is not valid', ResponseStatus::BadRequest);
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
2022-11-28 23:05:44 +01:00
|
|
|
|
|
|
|
return new RedirectResponse($panel->uri('/login/'));
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'methods' => ['POST'],
|
2023-05-20 21:26:49 +02:00
|
|
|
'types' => ['HTTP', 'XHR'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-11-28 23:05:44 +01:00
|
|
|
|
2024-10-05 20:08:22 +02:00
|
|
|
'panel.checkAssets' => [
|
|
|
|
'action' => static function (Config $config, ViewFactory $viewFactory) {
|
|
|
|
$path = $config->get('system.panel.paths.assets');
|
2024-10-06 16:49:44 +02:00
|
|
|
$assets = ['css/panel.min.css', 'js/app.min.js'];
|
2024-10-05 20:08:22 +02:00
|
|
|
|
|
|
|
foreach ($assets as $asset) {
|
|
|
|
$assetPath = FileSystem::joinPaths($path, $asset);
|
|
|
|
if (!FileSystem::isFile($assetPath, assertExists: false)) {
|
|
|
|
$view = $viewFactory->make('errors.panel.assets');
|
|
|
|
return new Response($view->render(), ResponseStatus::InternalServerError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
2022-11-27 21:21:19 +01:00
|
|
|
'panel.register' => [
|
2024-10-05 14:44:20 +02:00
|
|
|
'action' => static function (Request $request, App $app, Site $site, Panel $panel) {
|
2022-11-27 21:21:19 +01:00
|
|
|
// Register panel if no user exists
|
2024-10-05 15:47:07 +02:00
|
|
|
if ($site->users()->isEmpty()) {
|
2023-07-29 22:39:28 +02:00
|
|
|
if (!$request->isLocalhost()) {
|
|
|
|
return new RedirectResponse($site->uri());
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
2022-11-28 23:05:44 +01:00
|
|
|
|
|
|
|
if ($panel->route() !== '/register/') {
|
|
|
|
return new RedirectResponse($panel->uri('/register/'));
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-05-20 21:26:49 +02:00
|
|
|
'methods' => ['GET', 'POST'],
|
2021-07-05 14:39:51 +02:00
|
|
|
],
|
2022-11-28 23:05:44 +01:00
|
|
|
|
2022-12-06 21:26:54 +01:00
|
|
|
'panel.redirectToLogin' => [
|
2024-10-05 15:47:07 +02:00
|
|
|
'action' => static function (Request $request, Site $site, Panel $panel) {
|
2021-07-05 14:39:51 +02:00
|
|
|
// Redirect to login if no user is logged
|
2024-10-25 01:13:00 +02:00
|
|
|
if (!$site->users()->isEmpty() && !$panel->isLoggedIn() && !in_array($panel->route(), ['/login/', '/logout/'], true)) {
|
|
|
|
$request->session()->set(AuthenticationController::SESSION_REDIRECT_KEY, $panel->route());
|
2022-11-28 23:05:44 +01:00
|
|
|
return new RedirectResponse($panel->uri('/login/'));
|
2021-07-05 14:39:51 +02:00
|
|
|
}
|
2023-05-20 21:26:49 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
2021-07-05 14:39:51 +02:00
|
|
|
];
|