From cdfe49d632ac3ee5465b9cf83980780746e46ec1 Mon Sep 17 00:00:00 2001 From: soufiane Date: Fri, 17 Mar 2023 18:41:20 +0100 Subject: [PATCH] wip #5789 @7:00 --- app/Http/Controllers/AjaxController.php | 26 ++- app/Http/Controllers/ClientController.php | 24 +- app/Http/Controllers/SignInController.php | 2 +- app/Http/Kernel.php | 1 + .../RedirectClientIfAuthenticated.php | 25 ++ .../Middleware/RedirectIfAuthenticated.php | 2 +- app/Models/AuthClient.php | 28 +++ app/Models/BackpackClient.php | 13 -- app/Models/{Clients.php => Client.php} | 12 +- app/Templates/Base.php | 1 + app/Templates/Home.php | 2 +- app/Templates/MyAccount.php | 18 ++ app/Templates/SignIn.php | 22 -- config/auth.php | 2 +- config/debugbar.php | 215 ++++++++++++++++++ resources/js/app.js | 7 +- resources/styles/common/setup.styl | 2 +- resources/styles/components/header.styl | 1 - resources/styles/components/navigation.styl | 7 +- resources/views/pages/home.blade.php | 2 +- resources/views/pages/sign_in.blade.php | 2 +- resources/views/partials/account.blade.php | 8 +- resources/views/partials/header.blade.php | 20 +- .../views/partials/nav-account.blade.php | 24 ++ routes/web.php | 5 +- 25 files changed, 392 insertions(+), 79 deletions(-) create mode 100644 app/Http/Middleware/RedirectClientIfAuthenticated.php create mode 100644 app/Models/AuthClient.php delete mode 100644 app/Models/BackpackClient.php rename app/Models/{Clients.php => Client.php} (88%) create mode 100644 app/Templates/MyAccount.php create mode 100644 config/debugbar.php create mode 100644 resources/views/partials/nav-account.blade.php diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 6372628..427f6e3 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -8,7 +8,7 @@ use App\Models\Product; use App\Models\QuoteRequest; use App\Models\Settings; use App\Models\News; -use App\Models\Clients; +use App\Models\Client; use Carbon\Carbon; use Cubist\Backpack\app\Http\Controllers\CubistFrontController; use Cubist\Backpack\app\Magic\PageData; @@ -18,7 +18,6 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Hash; -use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Auth; class AjaxController extends CubistFrontController @@ -288,15 +287,14 @@ class AjaxController extends CubistFrontController throw new ValidationException($validator); } - $email = Clients::where('email', $request->email)->get(); + $email = Client::where('email', $request->email)->get(); return $email; } - public function signin(Request $request) - { + public function signin(Request $request) { $validation = [ 'email' => 'required|email', - 'password' => 'required', + 'password' => 'required' ]; $validator = Validator::make($request->all(), $validation); @@ -305,15 +303,21 @@ class AjaxController extends CubistFrontController throw new ValidationException($validator); } + $status = Client::where('email', $request->email)->get('status'); + if (!$status) { + throw ValidationException::withMessages(['email' => __('Le compte lié à cette adresse est en cours de validation')]); + } + $validator->validate(); $data = $validator->validated(); - if (Auth::guard('web-clients')->attempt($data)) { - $request->session()->regenerate(); + $remember = $request->stay_log ? true : false; - var_dump(Auth::user()); + if (Auth::guard('web-clients')->attempt($data, $remember)) { + $request->session()->regenerate(); + return Auth::guard('web-clients')->user(); }else{ - return 'pas ok'; + return false; } } @@ -346,7 +350,7 @@ class AjaxController extends CubistFrontController $data['status'] = 0; $data['password'] = Hash::make($data['password']); - $client = new Clients($data); + $client = new Client($data); $client->save(); return $data; diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 3678462..600afc1 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -1,14 +1,28 @@ user(); + public function logout(Request $request): RedirectResponse + { + //Auth::guard('web-clients')->logout(); + + $request->session()->invalidate(); + + $request->session()->regenerateToken(); + + return redirect('/se-connecter'); } } diff --git a/app/Http/Controllers/SignInController.php b/app/Http/Controllers/SignInController.php index 627c536..b4bcd69 100644 --- a/app/Http/Controllers/SignInController.php +++ b/app/Http/Controllers/SignInController.php @@ -10,7 +10,7 @@ use Illuminate\Http\Request; class SignInController extends CubistFrontController { - public function view(Request $request, $id) + public function view(Request $request) { return view('pages.signin'); } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 55cc452..c08ad9d 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -64,6 +64,7 @@ class Kernel extends HttpKernel 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'client' => \App\Http\Middleware\RedirectClientIfAuthenticated::class, 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, diff --git a/app/Http/Middleware/RedirectClientIfAuthenticated.php b/app/Http/Middleware/RedirectClientIfAuthenticated.php new file mode 100644 index 0000000..3e11903 --- /dev/null +++ b/app/Http/Middleware/RedirectClientIfAuthenticated.php @@ -0,0 +1,25 @@ +is('se-connecter') && Auth::guard('web-clients')->check()) { + return redirect('/'); + } + + return $next($request); + } +} diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index e4cec9c..e27860e 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -18,7 +18,7 @@ class RedirectIfAuthenticated public function handle($request, Closure $next, $guard = null) { if (Auth::guard($guard)->check()) { - return redirect('/home'); + return redirect('/'); } return $next($request); diff --git a/app/Models/AuthClient.php b/app/Models/AuthClient.php new file mode 100644 index 0000000..ada747e --- /dev/null +++ b/app/Models/AuthClient.php @@ -0,0 +1,28 @@ + 'clients', 'singular' => 'Client', - 'plural' => 'Clients']; + 'plural' => 'Client']; public function setFields() { @@ -71,5 +72,12 @@ class Clients extends CubistMagicAbstractModel 'column' => true, 'tab' => 'Informations client' ]); + + $this->addField([ + 'name' => 'remember_token', + 'label' => 'remember_token', + 'type' => 'Text', + 'column' => true + ]); } } diff --git a/app/Templates/Base.php b/app/Templates/Base.php index 694bb74..7ba53a9 100644 --- a/app/Templates/Base.php +++ b/app/Templates/Base.php @@ -3,6 +3,7 @@ namespace App\Templates; use Cubist\Backpack\app\Template\TemplatePage; +use http\Env\Request; class Base extends TemplatePage { diff --git a/app/Templates/Home.php b/app/Templates/Home.php index fb2ae07..b6aff91 100644 --- a/app/Templates/Home.php +++ b/app/Templates/Home.php @@ -78,7 +78,7 @@ class Home extends Base 'type' => 'BunchOfFieldsMultiple', 'bunch' => 'App\SubForms\Logo', 'label' => 'Logos', - 'tab' => 'Clients']); + 'tab' => 'Client']); } // Set extra data for Home blade view diff --git a/app/Templates/MyAccount.php b/app/Templates/MyAccount.php new file mode 100644 index 0000000..b04fb45 --- /dev/null +++ b/app/Templates/MyAccount.php @@ -0,0 +1,18 @@ +removeField('intro'); - - $this->addField(['name' => 'page_heading', - 'type' => 'Text', - 'label' => 'Titre de la page', - 'tab' => 'Contenus' - ]); - - $this->addField([ - 'name' => 'email', - 'type' => 'Email', - 'label' => 'Email', - 'tab' => $form_login - ]); - - - // Enable form - $this->addForm(); } } diff --git a/config/auth.php b/config/auth.php index 86aae42..b766952 100644 --- a/config/auth.php +++ b/config/auth.php @@ -77,7 +77,7 @@ return [ 'clients' => [ 'driver' => 'eloquent', - 'model' => App\Models\BackpackClient::class, + 'model' => App\Models\AuthClient::class, ] // 'users' => [ diff --git a/config/debugbar.php b/config/debugbar.php new file mode 100644 index 0000000..6aed981 --- /dev/null +++ b/config/debugbar.php @@ -0,0 +1,215 @@ + env('DEBUGBAR_ENABLED', null), + 'except' => [ + 'telescope*', + 'horizon*' + ], + + /* + |-------------------------------------------------------------------------- + | Storage settings + |-------------------------------------------------------------------------- + | + | DebugBar stores data for session/ajax requests. + | You can disable this, so the debugbar stores data in headers/session, + | but this can cause problems with large data collectors. + | By default, file storage (in the storage folder) is used. Redis and PDO + | can also be used. For PDO, run the package migrations first. + | + */ + 'storage' => [ + 'enabled' => true, + 'driver' => 'file', // redis, file, pdo, custom + 'path' => storage_path('debugbar'), // For file driver + 'connection' => null, // Leave null for default connection (Redis/PDO) + 'provider' => '' // Instance of StorageInterface for custom driver + ], + + /* + |-------------------------------------------------------------------------- + | Vendors + |-------------------------------------------------------------------------- + | + | Vendor files are included by default, but can be set to false. + | This can also be set to 'js' or 'css', to only include javascript or css vendor files. + | Vendor files are for css: font-awesome (including fonts) and highlight.js (css files) + | and for js: jquery and and highlight.js + | So if you want syntax highlighting, set it to true. + | jQuery is set to not conflict with existing jQuery scripts. + | + */ + + 'include_vendors' => true, + + /* + |-------------------------------------------------------------------------- + | Capture Ajax Requests + |-------------------------------------------------------------------------- + | + | The Debugbar can capture Ajax requests and display them. If you don't want this (ie. because of errors), + | you can use this option to disable sending the data through the headers. + | + | Optionally, you can also send ServerTiming headers on ajax requests for the Chrome DevTools. + */ + + 'capture_ajax' => true, + 'add_ajax_timing' => false, + + /* + |-------------------------------------------------------------------------- + | Custom Error Handler for Deprecated warnings + |-------------------------------------------------------------------------- + | + | When enabled, the Debugbar shows deprecated warnings for Symfony components + | in the Messages tab. + | + */ + 'error_handler' => false, + + /* + |-------------------------------------------------------------------------- + | Clockwork integration + |-------------------------------------------------------------------------- + | + | The Debugbar can emulate the Clockwork headers, so you can use the Chrome + | Extension, without the server-side code. It uses Debugbar collectors instead. + | + */ + 'clockwork' => false, + + /* + |-------------------------------------------------------------------------- + | DataCollectors + |-------------------------------------------------------------------------- + | + | Enable/disable DataCollectors + | + */ + + 'collectors' => [ + 'phpinfo' => true, // Php version + 'messages' => true, // Messages + 'time' => true, // Time Datalogger + 'memory' => true, // Memory usage + 'exceptions' => true, // Exception displayer + 'log' => true, // Logs from Monolog (merged in messages if enabled) + 'db' => true, // Show database (PDO) queries and bindings + 'views' => true, // Views with their data + 'route' => true, // Current route information + 'auth' => true, // Display Laravel authentication status + 'gate' => true, // Display Laravel Gate checks + 'session' => true, // Display session data + 'symfony_request' => true, // Only one can be enabled.. + 'mail' => true, // Catch mail messages + 'laravel' => false, // Laravel version and environment + 'events' => false, // All events fired + 'default_request' => false, // Regular or special Symfony request logger + 'logs' => false, // Add the latest log messages + 'files' => false, // Show the included files + 'config' => false, // Display config settings + 'cache' => false, // Display cache events + 'models' => true, // Display models + 'livewire' => true, // Display Livewire (when available) + ], + + /* + |-------------------------------------------------------------------------- + | Extra options + |-------------------------------------------------------------------------- + | + | Configure some DataCollectors + | + */ + + 'options' => [ + 'auth' => [ + 'show_name' => true, // Also show the users name/email in the debugbar + ], + 'db' => [ + 'with_params' => true, // Render SQL with the parameters substituted + 'backtrace' => true, // Use a backtrace to find the origin of the query in your files. + 'backtrace_exclude_paths' => [], // Paths to exclude from backtrace. (in addition to defaults) + 'timeline' => false, // Add the queries to the timeline + 'explain' => [ // Show EXPLAIN output on queries + 'enabled' => false, + 'types' => ['SELECT'], // // workaround ['SELECT'] only. https://github.com/barryvdh/laravel-debugbar/issues/888 ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; for MySQL 5.6.3+ + ], + 'hints' => false, // Show hints for common mistakes + ], + 'mail' => [ + 'full_log' => false + ], + 'views' => [ + 'data' => false, //Note: Can slow down the application, because the data can be quite large.. + ], + 'route' => [ + 'label' => true // show complete route on bar + ], + 'logs' => [ + 'file' => null + ], + 'cache' => [ + 'values' => true // collect cache values + ], + ], + + /* + |-------------------------------------------------------------------------- + | Inject Debugbar in Response + |-------------------------------------------------------------------------- + | + | Usually, the debugbar is added just before , by listening to the + | Response after the App is done. If you disable this, you have to add them + | in your template yourself. See http://phpdebugbar.com/docs/rendering.html + | + */ + + 'inject' => true, + + /* + |-------------------------------------------------------------------------- + | DebugBar route prefix + |-------------------------------------------------------------------------- + | + | Sometimes you want to set route prefix to be used by DebugBar to load + | its resources from. Usually the need comes from misconfigured web server or + | from trying to overcome bugs like this: http://trac.nginx.org/nginx/ticket/97 + | + */ + 'route_prefix' => '_debugbar', + + /* + |-------------------------------------------------------------------------- + | DebugBar route domain + |-------------------------------------------------------------------------- + | + | By default DebugBar route served from the same domain that request served. + | To override default domain, specify it as a non-empty value. + */ + 'route_domain' => null, + + /* + |-------------------------------------------------------------------------- + | DebugBar theme + |-------------------------------------------------------------------------- + | + | Switches between light and dark theme. If set to auto it will respect system preferences + | Possible values: auto, light, dark + */ + 'theme' => 'auto', +]; diff --git a/resources/js/app.js b/resources/js/app.js index d44a1b9..ab39614 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -172,17 +172,16 @@ const app = new Vue({ form = document.getElementById('signin-form'), data = new FormData(form) - console.log(form) - axios.post('/ajax/signin', data) .then(function (response) { // - let lastVisitedUrl = document.referrer; + + let lastVisitedUrl = document.querySelector('[name="previous-url"]').getAttribute('content'); let homeUrl = window.location.origin; if(lastVisitedUrl){ if(lastVisitedUrl.includes('pm-instrumentation')){ - history.back() + window.location.replace(lastVisitedUrl) }else{ window.location.replace(homeUrl) } diff --git a/resources/styles/common/setup.styl b/resources/styles/common/setup.styl index f5d7b98..a5e9be0 100644 --- a/resources/styles/common/setup.styl +++ b/resources/styles/common/setup.styl @@ -8,7 +8,7 @@ $base-width = 1920px // Basis for vw unit calculations on large screens $content-max-width = $base-width * 0.9 // Allows 5% either side $header-height = 134px -$header-height-minimized = 60px +$header-height-minimized = 75px $transition-duration = 500ms // Gutters (assumed to always be a vw, vh or % unit) diff --git a/resources/styles/components/header.styl b/resources/styles/components/header.styl index 849863a..e799d62 100644 --- a/resources/styles/components/header.styl +++ b/resources/styles/components/header.styl @@ -26,7 +26,6 @@ width: 34px height: 36px - .site-header @apply bg-navy text-white text-lg font-display font-medium antialiased fixed top-0 diff --git a/resources/styles/components/navigation.styl b/resources/styles/components/navigation.styl index 74b44f1..6c0ba8b 100644 --- a/resources/styles/components/navigation.styl +++ b/resources/styles/components/navigation.styl @@ -5,8 +5,8 @@ to opacity: 1 -.nav-primary - @apply flex mx-auto px-8 +.nav-primary, +.account-header // Trigger for submenus, at any depth li:hover > ul @@ -95,6 +95,9 @@ overflow: hidden text-overflow: ellipsis +.nav-primary + @apply flex mx-auto px-8 + #mobile-nav +below($breakpoint-menu) display: block diff --git a/resources/views/pages/home.blade.php b/resources/views/pages/home.blade.php index 20f5383..793a12e 100644 --- a/resources/views/pages/home.blade.php +++ b/resources/views/pages/home.blade.php @@ -153,7 +153,7 @@ @endif @if(config('features.clients')) - {{-- Our Clients --}} + {{-- Our Client --}} diff --git a/resources/views/pages/sign_in.blade.php b/resources/views/pages/sign_in.blade.php index 8b9591b..0edef20 100644 --- a/resources/views/pages/sign_in.blade.php +++ b/resources/views/pages/sign_in.blade.php @@ -57,7 +57,7 @@
diff --git a/resources/views/partials/account.blade.php b/resources/views/partials/account.blade.php index 15348a1..54bc12b 100644 --- a/resources/views/partials/account.blade.php +++ b/resources/views/partials/account.blade.php @@ -1,4 +1,10 @@ - + diff --git a/resources/views/partials/header.blade.php b/resources/views/partials/header.blade.php index c92e637..811deae 100644 --- a/resources/views/partials/header.blade.php +++ b/resources/views/partials/header.blade.php @@ -31,17 +31,17 @@ - @php - var_dump(Auth::user()); - @endphp - @guest - - @include('partials.account') - - @endguest + @if (config('features.quote')) check()) + +@endif diff --git a/routes/web.php b/routes/web.php index b24ceec..e1a381b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,4 +1,7 @@ where(['page' => '^(((?=(?!admin))(?=(?!\/)).))*$', 'subs' => '.*']); + ->where(['page' => '^(((?=(?!admin))(?=(?!\/)).))*$', 'subs' => '.*']) + ->middleware('client'); -- 2.39.5