Added check for setup in Setting model

This commit is contained in:
snipe 2016-05-14 16:09:00 -07:00
parent 5b829884b8
commit 415b60a293
3 changed files with 32 additions and 16 deletions

View file

@ -34,7 +34,6 @@ class Kernel extends HttpKernel
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\App\Http\Middleware\VerifyCsrfToken::class, \App\Http\Middleware\VerifyCsrfToken::class,
\App\Http\Middleware\CheckLocale::class, \App\Http\Middleware\CheckLocale::class,
\App\Http\Middleware\CheckForSetup::class,
], ],
'api' => [ 'api' => [

View file

@ -7,36 +7,30 @@ use Config;
use Route; use Route;
use Schema; use Schema;
use App\Models\User; use App\Models\User;
use App\Models\Setting;
class CheckForSetup class CheckForSetup
{ {
public function handle($request, Closure $next, $guard = null) public function handle($request, Closure $next, $guard = null)
{ {
try { if (Setting::setupCompleted()) {
$users_table_exists = Schema::hasTable('users'); if ($request->is('setup*')) {
$settings_table_exists = Schema::hasTable('settings');
if ($users_table_exists && $settings_table_exists) {
$usercount = User::withTrashed()->count();
if (($usercount > 0) && (Route::is('setup*'))) {
return redirect(config('app.url')); return redirect(config('app.url'));
} else { } else {
return $next($request); return $next($request);
} }
} else { } else {
if (!$request->is('setup*')) {
return redirect(config('app.url').'/setup')->with('Request',$request);
}
return $next($request); return $next($request);
} }
} catch (\Exception $e) {
return $next($request);
}
} }
} }

View file

@ -3,6 +3,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Watson\Validating\ValidatingTrait; use Watson\Validating\ValidatingTrait;
use Schema;
class Setting extends Model class Setting extends Model
{ {
@ -40,6 +41,28 @@ class Setting extends Model
return $static_cache; return $static_cache;
} }
public static function setupCompleted() {
$users_table_exists = Schema::hasTable('users');
$settings_table_exists = Schema::hasTable('settings');
if ($users_table_exists && $settings_table_exists) {
$usercount = User::withTrashed()->count();
if ($usercount > 0) {
return true;
}
return false;
} else {
return false;
}
return false;
}
public function lar_ver() public function lar_ver()
{ {
$app = \App::getFacadeApplication(); $app = \App::getFacadeApplication();