mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Added check for setup in Setting model
This commit is contained in:
parent
5b829884b8
commit
415b60a293
|
@ -34,7 +34,6 @@ class Kernel extends HttpKernel
|
|||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\App\Http\Middleware\CheckLocale::class,
|
||||
\App\Http\Middleware\CheckForSetup::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
|
|
|
@ -7,36 +7,30 @@ use Config;
|
|||
use Route;
|
||||
use Schema;
|
||||
use App\Models\User;
|
||||
use App\Models\Setting;
|
||||
|
||||
class CheckForSetup
|
||||
{
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
|
||||
try {
|
||||
if (Setting::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) && (Route::is('setup*'))) {
|
||||
if ($request->is('setup*')) {
|
||||
return redirect(config('app.url'));
|
||||
} else {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!$request->is('setup*')) {
|
||||
return redirect(config('app.url').'/setup')->with('Request',$request);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ namespace App\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
use Schema;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
|
@ -40,6 +41,28 @@ class Setting extends Model
|
|||
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()
|
||||
{
|
||||
$app = \App::getFacadeApplication();
|
||||
|
|
Loading…
Reference in a new issue