separate checking installation as a middleware

This commit is contained in:
printempw 2017-01-18 22:42:50 +08:00
parent 294b008880
commit 13e51464f6
4 changed files with 26 additions and 19 deletions

View File

@ -18,31 +18,18 @@ class SetupController extends Controller
{
public function welcome()
{
// already installed
if (self::checkTablesExist()) {
return view('setup.locked');
} else {
$config = config('database.connections.mysql');
$config = config('database.connections.mysql');
return view('setup.wizard.welcome')->with('server', "{$config['username']}@{$config['host']}");
}
return view('setup.wizard.welcome')->with('server', "{$config['username']}@{$config['host']}");
}
public function info()
{
if (self::checkTablesExist()) {
return view('setup.locked');
}
return view('setup.wizard.info');
}
public function finish(Request $request)
{
if (self::checkTablesExist()) {
return view('setup.locked');
}
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6|max:16|confirmed',

View File

@ -47,6 +47,7 @@ class Kernel extends HttpKernel
'auth' => \App\Http\Middleware\CheckAuthenticated::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'admin' => \App\Http\Middleware\CheckAdministrator::class,
'player' => \App\Http\Middleware\CheckPlayerExist::class
'player' => \App\Http\Middleware\CheckPlayerExist::class,
'setup' => \App\Http\Middleware\CheckInstallation::class,
];
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use App\Http\Controllers\SetupController;
class CheckInstallation
{
public function handle($request, \Closure $next)
{
if (SetupController::checkTablesExist()) {
return response()->view('setup.locked');
}
return $next($request);
}
}

View File

@ -16,9 +16,11 @@
*/
Route::group(['prefix' => 'setup'], function ()
{
Route::get ('/', 'SetupController@welcome');
Route::get ('/info', 'SetupController@info');
Route::post('/finish', 'SetupController@finish');
Route::group(['middleware' => 'setup'], function () {
Route::get ('/', 'SetupController@welcome');
Route::get ('/info', 'SetupController@info');
Route::post('/finish', 'SetupController@finish');
});
Route::get ('/update', 'SetupController@update');
Route::post('/update', 'SetupController@doUpdate');