From f28e2a24dadbe7f8136424b7621cec30c75114e3 Mon Sep 17 00:00:00 2001 From: mychidarko Date: Mon, 11 Nov 2024 10:06:33 +0000 Subject: [PATCH] feat: migrate aloe to fs v2 --- src/Command/AuthScaffoldCommand.php | 4 +- src/Command/DevToolsCommand.php | 6 +- src/Command/MailSetupCommand.php | 1 - src/Command/ViewInstallCommand.php | 117 ++++----------- .../{ => bare-ui/app}/routes/_frontend.php | 0 .../app/views}/_inertia.view.php | 0 .../app/views}/js/Pages/Hello.jsx | 0 .../app/views}/js/Pages/Login.jsx | 0 .../bare-ui => bare-ui/app/views}/js/app.jsx | 0 .../react/{root => bare-ui}/vite.config.js | 0 .../blade}/app/routes/_frontend.php | 0 .../app/views}/_inertia.blade.php | 0 .../app/views}/js/Pages/Hello.jsx | 0 .../app/views}/js/Pages/Login.jsx | 0 .../blade => blade/app/views}/js/app.jsx | 0 src/Command/themes/react/blade/vite.config.js | 13 ++ .../bare-ui/{ => app/views}/_inertia.view.php | 0 .../{ => app/views}/js/Pages/Hello.vue | 0 .../vue/bare-ui/{ => app/views}/js/app.js | 0 .../themes/vue/{ => bare-ui}/vite.config.js | 0 .../themes/vue/blade/app/routes/_frontend.php | 5 + .../blade/{ => app/views}/_inertia.blade.php | 0 .../blade/{ => app/views}/js/Pages/Hello.vue | 0 .../vue/blade/{ => app/views}/js/app.js | 0 src/Command/themes/vue/blade/vite.config.js | 20 +++ src/Installer.php | 50 +++---- src/Package.php | 2 +- .../controllers/Auth/AccountController.php | 10 +- ...Controller.php => DashboardController.php} | 4 +- .../app/controllers/Auth/LoginController.php | 44 +++--- .../controllers/Auth/RegisterController.php | 43 +++--- src/Scaffold/SessionAuth/app/routes/_auth.php | 43 ++++-- .../app/views/components/topnav.blade.php | 135 ++++++++++++++---- .../app/views/layouts/auth.blade.php | 30 ++-- .../app/views/layouts/dashboard.blade.php | 24 ++++ .../app/views/pages/auth/account.blade.php | 25 +--- .../app/views/pages/auth/home.blade.php | 31 ++-- .../app/views/pages/auth/login.blade.php | 51 ++++--- .../app/views/pages/auth/register.blade.php | 67 +++++---- 39 files changed, 404 insertions(+), 321 deletions(-) rename src/Command/themes/react/{ => bare-ui/app}/routes/_frontend.php (100%) rename src/Command/themes/react/{views/bare-ui => bare-ui/app/views}/_inertia.view.php (100%) rename src/Command/themes/react/{views/bare-ui => bare-ui/app/views}/js/Pages/Hello.jsx (100%) rename src/Command/themes/react/{views/bare-ui => bare-ui/app/views}/js/Pages/Login.jsx (100%) rename src/Command/themes/react/{views/bare-ui => bare-ui/app/views}/js/app.jsx (100%) rename src/Command/themes/react/{root => bare-ui}/vite.config.js (100%) rename src/Command/themes/{vue => react/blade}/app/routes/_frontend.php (100%) rename src/Command/themes/react/{views/blade => blade/app/views}/_inertia.blade.php (100%) rename src/Command/themes/react/{views/blade => blade/app/views}/js/Pages/Hello.jsx (100%) rename src/Command/themes/react/{views/blade => blade/app/views}/js/Pages/Login.jsx (100%) rename src/Command/themes/react/{views/blade => blade/app/views}/js/app.jsx (100%) create mode 100644 src/Command/themes/react/blade/vite.config.js rename src/Command/themes/vue/bare-ui/{ => app/views}/_inertia.view.php (100%) rename src/Command/themes/vue/bare-ui/{ => app/views}/js/Pages/Hello.vue (100%) rename src/Command/themes/vue/bare-ui/{ => app/views}/js/app.js (100%) rename src/Command/themes/vue/{ => bare-ui}/vite.config.js (100%) create mode 100644 src/Command/themes/vue/blade/app/routes/_frontend.php rename src/Command/themes/vue/blade/{ => app/views}/_inertia.blade.php (100%) rename src/Command/themes/vue/blade/{ => app/views}/js/Pages/Hello.vue (100%) rename src/Command/themes/vue/blade/{ => app/views}/js/app.js (100%) create mode 100644 src/Command/themes/vue/blade/vite.config.js rename src/Scaffold/SessionAuth/app/controllers/Auth/{HomeController.php => DashboardController.php} (62%) mode change 100755 => 100644 src/Scaffold/SessionAuth/app/routes/_auth.php create mode 100644 src/Scaffold/SessionAuth/app/views/layouts/dashboard.blade.php diff --git a/src/Command/AuthScaffoldCommand.php b/src/Command/AuthScaffoldCommand.php index 6773d9c..c7b0953 100755 --- a/src/Command/AuthScaffoldCommand.php +++ b/src/Command/AuthScaffoldCommand.php @@ -3,7 +3,6 @@ namespace Aloe\Command; use Aloe\Installer; -use Leaf\FS; use Illuminate\Support\Str; class AuthScaffoldCommand extends \Aloe\Command @@ -34,7 +33,6 @@ protected function handle() $installablesDir = $this->installable($driver); Installer::magicCopy($installablesDir); - Installer::installRoutes("$installablesDir/app/routes/"); $this->info('Authentication generated successfully.'); @@ -43,6 +41,6 @@ protected function handle() protected function installable($driver) { - return dirname(__DIR__) . '/Scaffold/' . Str::studly($driver . 'Auth'); + return dirname(__DIR__) . '/Scaffold/' . Str::studly("{$driver}Auth"); } } diff --git a/src/Command/DevToolsCommand.php b/src/Command/DevToolsCommand.php index 8afeb27..410d829 100755 --- a/src/Command/DevToolsCommand.php +++ b/src/Command/DevToolsCommand.php @@ -3,7 +3,7 @@ namespace Aloe\Command; use Aloe\Installer; -use Leaf\FS; +use Leaf\FS\Storage; class DevToolsCommand extends \Aloe\Command { @@ -18,7 +18,7 @@ protected function handle() $this->comment('Installing leaf devtools routes...'); - $rootFile = FS::readFile(Config::rootPath(PublicPath('index.php'))); + $rootFile = Storage::read(Config::rootPath(PublicPath('index.php'))); $rootFile = str_replace( "/* |-------------------------------------------------------------------------- @@ -51,7 +51,7 @@ protected function handle() $rootFile = str_replace("\n\n\n", "\n", $rootFile); - FS::writeFile(Config::rootPath(PublicPath('index.php')), $rootFile); + Storage::writeFile(Config::rootPath(PublicPath('index.php')), $rootFile); $this->info('Leaf devtools installed successfully!'); diff --git a/src/Command/MailSetupCommand.php b/src/Command/MailSetupCommand.php index 4b82dc0..5613679 100755 --- a/src/Command/MailSetupCommand.php +++ b/src/Command/MailSetupCommand.php @@ -3,7 +3,6 @@ namespace Aloe\Command; use Aloe\Installer; -use Leaf\FS; class MailSetupCommand extends \Aloe\Command { diff --git a/src/Command/ViewInstallCommand.php b/src/Command/ViewInstallCommand.php index a8c7cd0..789c5d3 100644 --- a/src/Command/ViewInstallCommand.php +++ b/src/Command/ViewInstallCommand.php @@ -78,16 +78,13 @@ protected function installBlade($output) }; if ($isMVCApp) { - $paths = require "$directory/config/paths.php"; - $viewsPath = trim($paths['views'] ?? 'app/views', '/'); - - \Leaf\FS::superCopy(__DIR__ . '/themes/blade', "$directory/$viewsPath"); + \Leaf\FS\Directory::copy(__DIR__ . '/themes/blade', $directory); $viewConfig = require "$directory/config/view.php"; $viewConfig['viewEngine'] = '\Leaf\Blade'; file_put_contents("$directory/config/view.php", 'writeln("\nšŸŽ‰ Blade setup successfully."); @@ -116,8 +113,7 @@ protected function installBareUi($output) $paths = require "$directory/config/paths.php"; $viewsPath = trim($paths['views'] ?? 'app/views', '/'); - \Leaf\FS::superCopy(__DIR__ . '/themes/bareui/theme', "$directory/$viewsPath"); - \Leaf\FS::superCopy(__DIR__ . '/themes/bareui/config', "$directory/config"); + \Leaf\FS\Directory::copy(__DIR__ . '/themes/bareui', $directory); if (file_exists("$directory/$viewsPath/index.blade.php")) { unlink("$directory/$viewsPath/index.blade.php"); @@ -147,7 +143,7 @@ protected function installBareUi($output) file_put_contents($indexFile, $index); } } else { - \Leaf\FS::superCopy(__DIR__ . '/themes/bareui', $directory); + \Leaf\FS\Directory::copy(__DIR__ . '/themes/bareui', $directory); } $output->writeln("\nšŸŽ‰ Bare UI setup successfully."); @@ -185,17 +181,10 @@ protected function installInertia($output) $isMVCApp = $this->isMVCApp(); $isBladeProject = $this->isBladeProject(); - foreach (glob(__DIR__ . '/themes/inertia/root/{,.}[!.,!..]*', GLOB_MARK | GLOB_BRACE) as $file) { - if (basename($file) === 'vite.config.js' && file_exists("$directory/vite.config.js")) { - continue; - } - - if (is_file($file)) { - copy($file, rtrim($directory, '/') . '/' . basename($file)); - } else { - \Leaf\FS::superCopy($file, rtrim($directory, '/') . '/' . basename($file)); - } - } + \Leaf\FS\Directory::copy( + __DIR__ . '/themes/inertia/' . ($isBladeProject ? 'blade' : 'bare-ui'), + $directory + ); if (!$isMVCApp) { $viteConfig = file_get_contents("$directory/vite.config.js"); @@ -205,14 +194,6 @@ protected function installInertia($output) $viteConfig ); file_put_contents("$directory/vite.config.js", $viteConfig); - } else { - $paths = require "$directory/config/paths.php"; - $viewsPath = trim($paths['views'] ?? 'app/views', '/'); - - \Leaf\FS::superCopy( - (__DIR__ . '/themes/inertia/views/' . ($isBladeProject ? 'blade' : 'bare-ui')), - "$directory/$viewsPath" - ); } $package = json_decode(file_get_contents("$directory/package.json"), true); @@ -270,41 +251,10 @@ protected function installReact($output) }; } - \Leaf\FS::superCopy(__DIR__ . '/themes/react/root', $directory); - - if ($isMVCApp) { - $paths = require "$directory/config/paths.php"; - $viewsPath = trim($paths['views'] ?? 'app/views', '/'); - $routesPath = trim($paths['routes'] ?? 'app/routes', '/'); - - \Leaf\FS::superCopy(__DIR__ . '/themes/react/routes', "$directory/$routesPath"); - \Leaf\FS::superCopy( - (__DIR__ . '/themes/react/views/' . ($isBladeProject ? 'blade' : 'bare-ui')), - "$directory/$viewsPath" - ); - } else { - \Leaf\FS::superCopy(__DIR__ . '/themes/react/routes', $directory); - \Leaf\FS::superCopy( - (__DIR__ . '/themes/react/views/' . ($isBladeProject ? 'blade' : 'bare-ui')), - $directory - ); - - $viteConfig = file_get_contents("$directory/vite.config.js"); - $viteConfig = str_replace( - "leaf({", - "leaf({\nhotFile: 'hot',", - $viteConfig - ); - file_put_contents("$directory/vite.config.js", $viteConfig); - - $inertiaView = file_get_contents("$directory/_inertia.$ext.php"); - $inertiaView = str_replace( - '', - '', - $inertiaView - ); - file_put_contents("$directory/_inertia.$ext.php", $inertiaView); - } + \Leaf\FS\Directory::copy( + __DIR__ . '/themes/react/' . ($isBladeProject ? 'blade' : 'bare-ui'), + $directory + ); $package = json_decode(file_get_contents("$directory/package.json"), true); $package['type'] = 'module'; @@ -350,24 +300,15 @@ protected function installTailwind($output) $isMVCApp = $this->isMVCApp(); - foreach (glob(__DIR__ . '/themes/tailwind/root/{,.}[!.,!..]*', GLOB_MARK | GLOB_BRACE) as $file) { - if (basename($file) === 'vite.config.js' && file_exists("$directory/vite.config.js")) { - continue; - } - - if (is_file($file)) { - copy($file, rtrim($directory, '/') . '/' . basename($file)); - } else { - \Leaf\FS::superCopy($file, rtrim($directory, '/') . '/' . basename($file)); - } - } + \Leaf\FS\Directory::copy( + __DIR__ . '/themes/tailwind/', + $directory + ); if ($isMVCApp) { $paths = require "$directory/config/paths.php"; $viewsPath = trim($paths['views'] ?? 'app/views', '/'); - \Leaf\FS::superCopy(__DIR__ . '/themes/tailwind/view', "$directory/$viewsPath"); - if (file_exists("$directory/app/views/js/app.js")) { $jsApp = file_get_contents("$directory/app/views/js/app.js"); if (strpos($jsApp, "import '../css/app.css';") === false) { @@ -382,8 +323,6 @@ protected function installTailwind($output) } } } else { - \Leaf\FS::superCopy(__DIR__ . '/themes/tailwind/view', $directory); - $viteConfig = file_get_contents("$directory/vite.config.js"); $viteConfig = str_replace( ["hotFile: 'hot',", 'hotFile: "hot",'], @@ -395,6 +334,7 @@ protected function installTailwind($output) "leaf({\nhotFile: 'hot',", $viteConfig ); + file_put_contents("$directory/vite.config.js", $viteConfig); if (file_exists("$directory/js/app.js")) { @@ -455,7 +395,7 @@ protected function installVite($output) $isMVCApp = $this->isMVCApp(); if (!file_exists("$directory/vite.config.js")) { - \Leaf\FS::superCopy(__DIR__ . '/themes/vite', $directory); + \Leaf\FS\Directory::copy(__DIR__ . '/themes/vite', $directory); } if (!$isMVCApp) { @@ -523,21 +463,14 @@ protected function installVue($output) }; } - \Leaf\FS::superCopy(__DIR__ . '/themes/vue/root', $directory); - - if ($isMVCApp) { - $paths = require "$directory/config/paths.php"; - $viewsPath = trim($paths['views'] ?? 'app/views', '/'); - $routesPath = trim($paths['routes'] ?? 'app/routes', '/'); + \Leaf\FS\Directory::copy( + __DIR__ . '/themes/vue/' . ($isBladeProject ? 'blade' : 'bare-ui'), + $directory + ); - \Leaf\FS::superCopy(__DIR__ . '/themes/vue/routes', "$directory/$routesPath"); - \Leaf\FS::superCopy( - (__DIR__ . '/themes/vue/views/' . ($isBladeProject ? 'blade' : 'bare-ui')), - "$directory/$viewsPath" - ); - } else { - \Leaf\FS::superCopy(__DIR__ . '/themes/vue/routes', $directory); - \Leaf\FS::superCopy( + if (!$isMVCApp) { + \Leaf\FS\Directory::copy(__DIR__ . '/themes/vue/routes', $directory); + \Leaf\FS\Directory::copy( (__DIR__ . '/themes/vue/views/' . ($isBladeProject ? 'blade' : 'bare-ui')), $directory ); diff --git a/src/Command/themes/react/routes/_frontend.php b/src/Command/themes/react/bare-ui/app/routes/_frontend.php similarity index 100% rename from src/Command/themes/react/routes/_frontend.php rename to src/Command/themes/react/bare-ui/app/routes/_frontend.php diff --git a/src/Command/themes/react/views/bare-ui/_inertia.view.php b/src/Command/themes/react/bare-ui/app/views/_inertia.view.php similarity index 100% rename from src/Command/themes/react/views/bare-ui/_inertia.view.php rename to src/Command/themes/react/bare-ui/app/views/_inertia.view.php diff --git a/src/Command/themes/react/views/bare-ui/js/Pages/Hello.jsx b/src/Command/themes/react/bare-ui/app/views/js/Pages/Hello.jsx similarity index 100% rename from src/Command/themes/react/views/bare-ui/js/Pages/Hello.jsx rename to src/Command/themes/react/bare-ui/app/views/js/Pages/Hello.jsx diff --git a/src/Command/themes/react/views/bare-ui/js/Pages/Login.jsx b/src/Command/themes/react/bare-ui/app/views/js/Pages/Login.jsx similarity index 100% rename from src/Command/themes/react/views/bare-ui/js/Pages/Login.jsx rename to src/Command/themes/react/bare-ui/app/views/js/Pages/Login.jsx diff --git a/src/Command/themes/react/views/bare-ui/js/app.jsx b/src/Command/themes/react/bare-ui/app/views/js/app.jsx similarity index 100% rename from src/Command/themes/react/views/bare-ui/js/app.jsx rename to src/Command/themes/react/bare-ui/app/views/js/app.jsx diff --git a/src/Command/themes/react/root/vite.config.js b/src/Command/themes/react/bare-ui/vite.config.js similarity index 100% rename from src/Command/themes/react/root/vite.config.js rename to src/Command/themes/react/bare-ui/vite.config.js diff --git a/src/Command/themes/vue/app/routes/_frontend.php b/src/Command/themes/react/blade/app/routes/_frontend.php similarity index 100% rename from src/Command/themes/vue/app/routes/_frontend.php rename to src/Command/themes/react/blade/app/routes/_frontend.php diff --git a/src/Command/themes/react/views/blade/_inertia.blade.php b/src/Command/themes/react/blade/app/views/_inertia.blade.php similarity index 100% rename from src/Command/themes/react/views/blade/_inertia.blade.php rename to src/Command/themes/react/blade/app/views/_inertia.blade.php diff --git a/src/Command/themes/react/views/blade/js/Pages/Hello.jsx b/src/Command/themes/react/blade/app/views/js/Pages/Hello.jsx similarity index 100% rename from src/Command/themes/react/views/blade/js/Pages/Hello.jsx rename to src/Command/themes/react/blade/app/views/js/Pages/Hello.jsx diff --git a/src/Command/themes/react/views/blade/js/Pages/Login.jsx b/src/Command/themes/react/blade/app/views/js/Pages/Login.jsx similarity index 100% rename from src/Command/themes/react/views/blade/js/Pages/Login.jsx rename to src/Command/themes/react/blade/app/views/js/Pages/Login.jsx diff --git a/src/Command/themes/react/views/blade/js/app.jsx b/src/Command/themes/react/blade/app/views/js/app.jsx similarity index 100% rename from src/Command/themes/react/views/blade/js/app.jsx rename to src/Command/themes/react/blade/app/views/js/app.jsx diff --git a/src/Command/themes/react/blade/vite.config.js b/src/Command/themes/react/blade/vite.config.js new file mode 100644 index 0000000..65b071f --- /dev/null +++ b/src/Command/themes/react/blade/vite.config.js @@ -0,0 +1,13 @@ +import { defineConfig } from 'vite'; +import leaf from '@leafphp/vite-plugin'; +import react from '@vitejs/plugin-react'; + +export default defineConfig({ + plugins: [ + leaf({ + input: ['app/views/js/app.jsx'], + refresh: true, + }), + react(), + ], +}); diff --git a/src/Command/themes/vue/bare-ui/_inertia.view.php b/src/Command/themes/vue/bare-ui/app/views/_inertia.view.php similarity index 100% rename from src/Command/themes/vue/bare-ui/_inertia.view.php rename to src/Command/themes/vue/bare-ui/app/views/_inertia.view.php diff --git a/src/Command/themes/vue/bare-ui/js/Pages/Hello.vue b/src/Command/themes/vue/bare-ui/app/views/js/Pages/Hello.vue similarity index 100% rename from src/Command/themes/vue/bare-ui/js/Pages/Hello.vue rename to src/Command/themes/vue/bare-ui/app/views/js/Pages/Hello.vue diff --git a/src/Command/themes/vue/bare-ui/js/app.js b/src/Command/themes/vue/bare-ui/app/views/js/app.js similarity index 100% rename from src/Command/themes/vue/bare-ui/js/app.js rename to src/Command/themes/vue/bare-ui/app/views/js/app.js diff --git a/src/Command/themes/vue/vite.config.js b/src/Command/themes/vue/bare-ui/vite.config.js similarity index 100% rename from src/Command/themes/vue/vite.config.js rename to src/Command/themes/vue/bare-ui/vite.config.js diff --git a/src/Command/themes/vue/blade/app/routes/_frontend.php b/src/Command/themes/vue/blade/app/routes/_frontend.php new file mode 100644 index 0000000..1b1022b --- /dev/null +++ b/src/Command/themes/vue/blade/app/routes/_frontend.php @@ -0,0 +1,5 @@ +get('/hello', function () { + inertia('Hello'); +}); diff --git a/src/Command/themes/vue/blade/_inertia.blade.php b/src/Command/themes/vue/blade/app/views/_inertia.blade.php similarity index 100% rename from src/Command/themes/vue/blade/_inertia.blade.php rename to src/Command/themes/vue/blade/app/views/_inertia.blade.php diff --git a/src/Command/themes/vue/blade/js/Pages/Hello.vue b/src/Command/themes/vue/blade/app/views/js/Pages/Hello.vue similarity index 100% rename from src/Command/themes/vue/blade/js/Pages/Hello.vue rename to src/Command/themes/vue/blade/app/views/js/Pages/Hello.vue diff --git a/src/Command/themes/vue/blade/js/app.js b/src/Command/themes/vue/blade/app/views/js/app.js similarity index 100% rename from src/Command/themes/vue/blade/js/app.js rename to src/Command/themes/vue/blade/app/views/js/app.js diff --git a/src/Command/themes/vue/blade/vite.config.js b/src/Command/themes/vue/blade/vite.config.js new file mode 100644 index 0000000..dd58302 --- /dev/null +++ b/src/Command/themes/vue/blade/vite.config.js @@ -0,0 +1,20 @@ +import { defineConfig } from "vite"; +import leaf from "@leafphp/vite-plugin"; +import vue from "@vitejs/plugin-vue"; + +export default defineConfig({ + plugins: [ + leaf({ + input: ["app/views/js/app.jsx"], + refresh: true, + }), + vue({ + template: { + transformAssetUrls: { + base: null, + includeAbsolute: false, + }, + }, + }), + ], +}); diff --git a/src/Installer.php b/src/Installer.php index 10885e4..971f56f 100755 --- a/src/Installer.php +++ b/src/Installer.php @@ -2,8 +2,8 @@ namespace Aloe; -use Leaf\FS; use Aloe\Command\Config; +use Leaf\FS\Directory; /** * Aloe Installer @@ -23,19 +23,21 @@ class Installer */ public static function magicCopy($installablesDir) { - $installables = FS::listFolders($installablesDir); + // $installables = FS::listFolders($installablesDir); - foreach ($installables as $installableDir) { - $dir = FS::listDir($installableDir); - $trueDir = str_replace($installablesDir, '', $installableDir); + // foreach ($installables as $installableDir) { + // $dir = FS::listDir($installableDir); + // $trueDir = str_replace($installablesDir, '', $installableDir); - foreach ($dir as $installable) { - FS::superCopy( - "$installableDir/$installable", - Config::rootpath("$trueDir/$installable") - ); - } - } + // foreach ($dir as $installable) { + // FS::superCopy( + // "$installableDir/$installable", + // Config::rootpath("$trueDir/$installable") + // ); + // } + // } + + Directory::copy($installablesDir, Config::rootpath()); } /** @@ -43,19 +45,19 @@ public static function magicCopy($installablesDir) */ public static function installRoutes($routesDir, $routeFile = 'index.php') { - $routeHome = Config::rootpath(RoutesPath($routeFile)); - $routeData = FS::readFile($routeHome); - $routes = FS::listDir($routesDir); + // $routeHome = Config::rootpath(RoutesPath($routeFile)); + // $routeData = FS::readFile($routeHome); + // $routes = FS::listDir($routesDir); - foreach ($routes as $route) { - $data = str_replace( - "require __DIR__ . '/$route';", - "", - $routeData - ); - FS::writeFile($routeHome, $data); - FS::append($routeHome, "require __DIR__ . '/$route';"); - } + // foreach ($routes as $route) { + // $data = str_replace( + // "require __DIR__ . '/$route';", + // "", + // $routeData + // ); + // FS::writeFile($routeHome, $data); + // FS::append($routeHome, "require __DIR__ . '/$route';"); + // } } /** diff --git a/src/Package.php b/src/Package.php index 8f75832..4c9864a 100644 --- a/src/Package.php +++ b/src/Package.php @@ -6,7 +6,7 @@ * Package * ---- * Meta info on aloe cli - * + * * @since 1.2.4 */ class Package diff --git a/src/Scaffold/SessionAuth/app/controllers/Auth/AccountController.php b/src/Scaffold/SessionAuth/app/controllers/Auth/AccountController.php index 828a542..7421498 100644 --- a/src/Scaffold/SessionAuth/app/controllers/Auth/AccountController.php +++ b/src/Scaffold/SessionAuth/app/controllers/Auth/AccountController.php @@ -6,8 +6,6 @@ class AccountController extends Controller { public function user() { - auth()->guard('auth'); - $user = auth()->user(['password']); if (!$user) { @@ -21,15 +19,13 @@ public function user() public function show_update() { - auth()->guard('auth'); - - $user = auth()->user(); + $user = auth()->data(); echo view('pages.auth.update', [ 'user' => auth()->id(), - 'username' => $user['username'] ?? null, - 'email' => $user['email'] ?? null, + // 'username' => $user['username'] ?? null, 'name' => $user['name'] ?? null, + 'email' => $user['email'] ?? null, ]); } diff --git a/src/Scaffold/SessionAuth/app/controllers/Auth/HomeController.php b/src/Scaffold/SessionAuth/app/controllers/Auth/DashboardController.php similarity index 62% rename from src/Scaffold/SessionAuth/app/controllers/Auth/HomeController.php rename to src/Scaffold/SessionAuth/app/controllers/Auth/DashboardController.php index 921ceae..65c5961 100644 --- a/src/Scaffold/SessionAuth/app/controllers/Auth/HomeController.php +++ b/src/Scaffold/SessionAuth/app/controllers/Auth/DashboardController.php @@ -2,12 +2,10 @@ namespace App\Controllers\Auth; -class HomeController extends Controller +class DashboardController extends Controller { public function index() { - auth()->guard('auth'); - echo view('pages.auth.home'); } } diff --git a/src/Scaffold/SessionAuth/app/controllers/Auth/LoginController.php b/src/Scaffold/SessionAuth/app/controllers/Auth/LoginController.php index 4aee081..1617964 100644 --- a/src/Scaffold/SessionAuth/app/controllers/Auth/LoginController.php +++ b/src/Scaffold/SessionAuth/app/controllers/Auth/LoginController.php @@ -2,43 +2,45 @@ namespace App\Controllers\Auth; -use App\Models\User; - class LoginController extends Controller { public function show() { - auth()->guard('guest'); + $form = flash()->display('form') ?? []; - echo view('pages.auth.login'); + echo view('pages.auth.login', array_merge($form, [ + 'errors' => flash()->display('error') ?? [] + ])); } public function store() { - auth()->guard('guest'); - - $data = request()->get(['username', 'password']); - - $this->form->validate([ - 'username' => 'validUsername', + $data = request()->validate([ + 'email' => 'email', + 'password' => 'min:8' ]); - $user = auth()->login($data); + if (!$data) { + response() + ->withFlash('form', request()->body()) + ->withFlash('error', request()->errors()) + ->redirect('/auth/login'); + } - if (!$user) { - echo view('pages.auth.login', array_merge($data, [ - 'errors' => array_merge( - auth()->errors(), - $this->form->errors() - ), - ])); + $success = auth()->login($data); + + if (!$success) { + response() + ->withFlash('form', request()->body()) + ->withFlash('error', request()->errors()) + ->redirect('/auth/login'); } + + response()->redirect('/dashboard'); } public function logout() { - auth()->guard('auth'); - - auth()->logout('GUARD_LOGIN'); + auth()->logout('/'); } } diff --git a/src/Scaffold/SessionAuth/app/controllers/Auth/RegisterController.php b/src/Scaffold/SessionAuth/app/controllers/Auth/RegisterController.php index cc9cf2f..0c80532 100644 --- a/src/Scaffold/SessionAuth/app/controllers/Auth/RegisterController.php +++ b/src/Scaffold/SessionAuth/app/controllers/Auth/RegisterController.php @@ -2,41 +2,42 @@ namespace App\Controllers\Auth; -use Leaf\Auth; - class RegisterController extends Controller { public function show() { - auth()->guard('guest'); + $form = flash()->display('form') ?? []; - echo view('pages.auth.register'); + echo view('pages.auth.register', array_merge($form, [ + 'errors' => flash()->display('error') ?? [] + ])); } public function store() { - auth()->guard('guest'); - - $credentials = request()->get(['name', 'username', 'email', 'password']); - - $this->form->validate([ - 'name' => 'required', - 'username' => 'validUsername', + $credentials = request()->validate([ + 'name' => 'string', 'email' => 'email', - 'password' => 'required' + 'password' => 'min:8', + 'confirmPassword*' => 'matchesValueOf:password' ]); - auth()->config('SESSION_ON_REGISTER', true); + if (!$credentials) { + return response() + ->withFlash('form', request()->body()) + ->withFlash('error', request()->errors()) + ->redirect('/auth/register'); + } - $user = auth()->register($credentials, [ - 'username', 'email' - ]); + $success = auth()->register($credentials); - if (!$user) { - echo view('pages.auth.register', array_merge( - ['errors' => array_merge(auth()->errors(), $this->form->errors())], - $credentials - )); + if (!$success) { + return response() + ->withFlash('form', request()->body()) + ->withFlash('error', auth()->errors()) + ->redirect('/auth/register'); } + + return response()->redirect('/dashboard'); } } diff --git a/src/Scaffold/SessionAuth/app/routes/_auth.php b/src/Scaffold/SessionAuth/app/routes/_auth.php old mode 100755 new mode 100644 index f79e6d3..729b5fb --- a/src/Scaffold/SessionAuth/app/routes/_auth.php +++ b/src/Scaffold/SessionAuth/app/routes/_auth.php @@ -1,18 +1,35 @@ group('/auth', function () { - app()->get('/login', 'Auth\LoginController@show'); - app()->post('/login', 'Auth\LoginController@store'); - app()->get('/register', 'Auth\RegisterController@show'); - app()->post('/register', 'Auth\RegisterController@store'); - app()->get('/logout', 'Auth\LoginController@logout'); - // Reset and recover account will be added later +auth()->middleware('auth.required', function () { + response()->redirect('/auth/login'); }); -app()->get('/home', 'Auth\HomeController@index'); - -app()->group('/user', function () { - app()->get('/', 'Auth\AccountController@user'); - app()->get('/update', 'Auth\AccountController@show_update'); - app()->post('/update', 'Auth\AccountController@update'); +auth()->middleware('auth.guest', function () { + response()->redirect('/dashboard'); }); + +app()->group('/auth', [ + 'middleware' => 'auth.guest', + function () { + app()->get('/login', 'Auth\LoginController@show'); + app()->post('/login', 'Auth\LoginController@store'); + app()->get('/register', 'Auth\RegisterController@show'); + app()->post('/register', 'Auth\RegisterController@store'); + // Reset and recover account will be added later + } +]); + +app()->post('/auth/logout', ['middleware' => 'auth.required', 'Auth\LoginController@logout']); + +app()->group('/dashboard', [ + 'middleware' => 'auth.required', + function () { + app()->get('/', 'Auth\DashboardController@index'); + + app()->group('/user', function () { + app()->get('/', 'Auth\AccountController@user'); + app()->get('/update', 'Auth\AccountController@show_update'); + app()->post('/update', 'Auth\AccountController@update'); + }); + } +]); diff --git a/src/Scaffold/SessionAuth/app/views/components/topnav.blade.php b/src/Scaffold/SessionAuth/app/views/components/topnav.blade.php index b064643..d20ed0a 100644 --- a/src/Scaffold/SessionAuth/app/views/components/topnav.blade.php +++ b/src/Scaffold/SessionAuth/app/views/components/topnav.blade.php @@ -1,30 +1,109 @@ - + + diff --git a/src/Scaffold/SessionAuth/app/views/layouts/auth.blade.php b/src/Scaffold/SessionAuth/app/views/layouts/auth.blade.php index d163455..c201366 100644 --- a/src/Scaffold/SessionAuth/app/views/layouts/auth.blade.php +++ b/src/Scaffold/SessionAuth/app/views/layouts/auth.blade.php @@ -2,29 +2,19 @@ - - - Login - {{ getenv('APP_NAME') ?? "Leaf MVC" }} - - - + + + Login - {{ getenv('APP_NAME') ?? 'Leaf MVC' }} + + + + {{ vite('css/app.css') }} - @include('components.topnav') - -
-
- -
-
-
- @yield('content') -
-
-
- - +
+ @yield('content') +
diff --git a/src/Scaffold/SessionAuth/app/views/layouts/dashboard.blade.php b/src/Scaffold/SessionAuth/app/views/layouts/dashboard.blade.php new file mode 100644 index 0000000..cb87b50 --- /dev/null +++ b/src/Scaffold/SessionAuth/app/views/layouts/dashboard.blade.php @@ -0,0 +1,24 @@ + + + + + + + Dashboard - {{ getenv('APP_NAME') ?? 'Leaf MVC' }} + + + + {{ vite('css/app.css') }} + + + + + + @include('components.topnav') + +
+ @yield('content') +
+ + + diff --git a/src/Scaffold/SessionAuth/app/views/pages/auth/account.blade.php b/src/Scaffold/SessionAuth/app/views/pages/auth/account.blade.php index 30754d3..dc9c0cd 100644 --- a/src/Scaffold/SessionAuth/app/views/pages/auth/account.blade.php +++ b/src/Scaffold/SessionAuth/app/views/pages/auth/account.blade.php @@ -1,30 +1,19 @@ - - - - - - Account - - - - - @include('components.topnav') +@extends('layouts.dashboard') +@section('content')

Account

This is the Account page.

- --}}
- Edit your account + Edit your account
- Logout + Logout
- - - +@endsection diff --git a/src/Scaffold/SessionAuth/app/views/pages/auth/home.blade.php b/src/Scaffold/SessionAuth/app/views/pages/auth/home.blade.php index b63dba2..a24315c 100644 --- a/src/Scaffold/SessionAuth/app/views/pages/auth/home.blade.php +++ b/src/Scaffold/SessionAuth/app/views/pages/auth/home.blade.php @@ -1,23 +1,14 @@ - - - - - - App Name - - - - - @include('components.topnav') +@extends('layouts.dashboard') + +@section('content') +
+
+

Hello šŸ‘‹

+
+

Welcome to your dashboard. You are logged in as {{ auth()->user()->name }}.

+
+
-
-

Home

-

This is the Home page.

-

You can edit your auth routes in app/routes/_auth.php

-

Auth controllers are in app/controllers/Auth/

- Go to account page
Logout
- - - +@endsection diff --git a/src/Scaffold/SessionAuth/app/views/pages/auth/login.blade.php b/src/Scaffold/SessionAuth/app/views/pages/auth/login.blade.php index 36f0b8e..342bbab 100644 --- a/src/Scaffold/SessionAuth/app/views/pages/auth/login.blade.php +++ b/src/Scaffold/SessionAuth/app/views/pages/auth/login.blade.php @@ -1,28 +1,39 @@ @extends('layouts.auth') @section('content') -
-
-

Login

-

- Sign into {{ _env('APP_NAME', 'Leaf MVC') }} -

-
-
-
- - {{ $errors['username'] ?? ($errors['auth'] ?? null) }} +
+
+ + {{ _env('APP_NAME') }} + +
+

Don't have a {{ _env('APP_NAME', 'Leaf MVC') }} account?

+ Sign up
-
- - {{ $errors['password'] ?? null }} +
+ + + form(); ?> + +
+ + +

{{ $errors['email'] ?? ($errors['auth'] ?? null) }}

- + +
+ + +

{{ $errors['password'] ?? null }}

+
+ + -
@endsection diff --git a/src/Scaffold/SessionAuth/app/views/pages/auth/register.blade.php b/src/Scaffold/SessionAuth/app/views/pages/auth/register.blade.php index cf455f3..f359d45 100644 --- a/src/Scaffold/SessionAuth/app/views/pages/auth/register.blade.php +++ b/src/Scaffold/SessionAuth/app/views/pages/auth/register.blade.php @@ -1,36 +1,51 @@ @extends('layouts.auth') @section('content') -
-
-

Sign Up

-

- Create your {{ _env('APP_NAME', 'Leaf MVC') }} account. -

-
-
-
- -

{{ $errors['name'] ?? null }}

+
+
+ + {{ _env('APP_NAME') }} + +
+

Already have a {{ _env('APP_NAME', 'Leaf MVC') }} account?

+ Log in
-
- -

{{ $errors['username'] ?? ($errors['auth'] ?? null) }}

+
+ + + form(); ?> + +
+ + +

{{ $errors['name'] ?? null }}

-
- -

{{ $errors['email'] ?? ($errors['auth'] ?? null) }}

+ +
+ + +

{{ $errors['email'] ?? ($errors['auth'] ?? null) }}

-
- -

{{ $errors['password'] ?? null }}

+ +
+ + +

{{ $errors['password'] ?? null }}

- + +
+ + +

{{ $errors['confirmPassword'] ?? null }}

+
+ + -
@endsection