From 1086eab6742e1e74d509d93ae69cd673e1802702 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Thu, 21 Feb 2019 18:20:03 +0300 Subject: [PATCH] moved wizard check to middleware --- app/Http/Controllers/Auth/Login.php | 7 +---- app/Http/Controllers/Wizard/Companies.php | 4 --- app/Http/Controllers/Wizard/Currencies.php | 14 --------- app/Http/Controllers/Wizard/Finish.php | 4 --- app/Http/Controllers/Wizard/Taxes.php | 12 ------- app/Http/Kernel.php | 2 +- .../Middleware/RedirectIfWizardCompleted.php | 31 +++++++++++++++++++ config/setting.php | 16 ++++++++++ 8 files changed, 49 insertions(+), 41 deletions(-) create mode 100644 app/Http/Middleware/RedirectIfWizardCompleted.php diff --git a/app/Http/Controllers/Auth/Login.php b/app/Http/Controllers/Auth/Login.php index f3639a60a..666d9feaf 100644 --- a/app/Http/Controllers/Auth/Login.php +++ b/app/Http/Controllers/Auth/Login.php @@ -79,12 +79,7 @@ class Login extends Controller return redirect($path); } - // Check wizard - if (!setting('general.wizard', false)) { - return redirect('wizard'); - } - - return redirect()->intended('/'); + return redirect()->intended('wizard'); } public function destroy() diff --git a/app/Http/Controllers/Wizard/Companies.php b/app/Http/Controllers/Wizard/Companies.php index 26061253e..882a25e04 100644 --- a/app/Http/Controllers/Wizard/Companies.php +++ b/app/Http/Controllers/Wizard/Companies.php @@ -19,10 +19,6 @@ class Companies extends Controller */ public function edit() { - if (setting('general.wizard', false)) { - return redirect('/'); - } - $company = Company::find(session('company_id')); $company->setSettings(); diff --git a/app/Http/Controllers/Wizard/Currencies.php b/app/Http/Controllers/Wizard/Currencies.php index 11ff3589c..ff0254283 100644 --- a/app/Http/Controllers/Wizard/Currencies.php +++ b/app/Http/Controllers/Wizard/Currencies.php @@ -13,16 +13,10 @@ class Currencies extends Controller /** * Show the form for editing the specified resource. * - * @param Currency $currency - * * @return Response */ public function index() { - if (setting('general.wizard', false)) { - return redirect('/'); - } - $currencies = Currency::all(); return view('wizard.currencies.index', compact('currencies')); @@ -35,10 +29,6 @@ class Currencies extends Controller */ public function create() { - if (setting('general.wizard', false)) { - return redirect('/'); - } - // Get current currencies $current = Currency::pluck('code')->toArray(); @@ -105,10 +95,6 @@ class Currencies extends Controller */ public function edit(Currency $currency) { - if (setting('general.wizard', false)) { - return redirect('/'); - } - // Get current currencies $current = Currency::pluck('code')->toArray(); diff --git a/app/Http/Controllers/Wizard/Finish.php b/app/Http/Controllers/Wizard/Finish.php index 004c924b4..d379aa547 100644 --- a/app/Http/Controllers/Wizard/Finish.php +++ b/app/Http/Controllers/Wizard/Finish.php @@ -17,10 +17,6 @@ class Finish extends Controller */ public function index() { - if (setting('general.wizard', false)) { - return redirect('/'); - } - setting()->set('general.wizard', true); // Save all settings diff --git a/app/Http/Controllers/Wizard/Taxes.php b/app/Http/Controllers/Wizard/Taxes.php index ce465ff76..cda3d1f45 100644 --- a/app/Http/Controllers/Wizard/Taxes.php +++ b/app/Http/Controllers/Wizard/Taxes.php @@ -15,10 +15,6 @@ class Taxes extends Controller */ public function index() { - if (setting('general.wizard', false)) { - return redirect('/'); - } - $taxes = Tax::all(); return view('wizard.taxes.index', compact('taxes')); @@ -31,10 +27,6 @@ class Taxes extends Controller */ public function create() { - if (setting('general.wizard', false)) { - return redirect('/'); - } - $html = view('wizard.taxes.create', compact('codes'))->render(); return response()->json([ @@ -75,10 +67,6 @@ class Taxes extends Controller */ public function edit(Tax $tax) { - if (setting('general.wizard', false)) { - return redirect('/'); - } - $item = $tax; $html = view('wizard.taxes.edit', compact('item'))->render(); diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 77767ca4a..fbb3cf5f3 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -36,6 +36,7 @@ class Kernel extends HttpKernel \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, \App\Http\Middleware\RedirectIfNotInstalled::class, + \App\Http\Middleware\RedirectIfWizardCompleted::class, \App\Http\Middleware\AddXHeader::class, 'company.settings', 'company.currencies', @@ -83,7 +84,6 @@ class Kernel extends HttpKernel 'signed-url', 'signed-url.company', \Illuminate\Routing\Middleware\SubstituteBindings::class, - \App\Http\Middleware\RedirectIfNotInstalled::class, \App\Http\Middleware\AddXHeader::class, 'company.settings', 'company.currencies', diff --git a/app/Http/Middleware/RedirectIfWizardCompleted.php b/app/Http/Middleware/RedirectIfWizardCompleted.php new file mode 100644 index 000000000..5a9621fe1 --- /dev/null +++ b/app/Http/Middleware/RedirectIfWizardCompleted.php @@ -0,0 +1,31 @@ +getPathInfo(), '/wizard')) { + return $next($request); + } + + // Wizard not completed + if (!setting('general.wizard', 0)) { + return $next($request); + } + + // Wizard completed, redirect to home + redirect()->intended('/')->send(); + } +} diff --git a/config/setting.php b/config/setting.php index 49f18bec9..686fb554e 100644 --- a/config/setting.php +++ b/config/setting.php @@ -67,4 +67,20 @@ return [ 'override' => [ ], + + /* + |-------------------------------------------------------------------------- + | Required Extra Columns + |-------------------------------------------------------------------------- + | + | The list of columns required to be set up + | + | Sample: + | "user_id", + | "tenant_id", + | + */ + 'required_extra_columns' => [ + 'company_id' + ], ];