2018-01-26 14:35:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
2018-02-01 20:13:58 +00:00
|
|
|
use Artisan;
|
2018-02-05 15:22:51 +00:00
|
|
|
use Schema;
|
2018-02-04 21:28:11 +00:00
|
|
|
use App\Setting;
|
2018-10-15 15:00:20 +00:00
|
|
|
use App\User;
|
2018-11-04 16:20:12 +00:00
|
|
|
use App\Application;
|
|
|
|
use App\Jobs\ProcessApps;
|
2018-01-26 14:35:01 +00:00
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2018-02-05 14:21:54 +00:00
|
|
|
|
2018-02-06 22:02:50 +00:00
|
|
|
if(!is_file(base_path('.env'))) {
|
|
|
|
touch(base_path('.env'));
|
|
|
|
Artisan::call('key:generate');
|
|
|
|
}
|
|
|
|
if(!is_file(database_path('app.sqlite'))) {
|
2018-01-29 20:14:40 +00:00
|
|
|
// first time setup
|
2018-02-06 22:02:50 +00:00
|
|
|
touch(database_path('app.sqlite'));
|
2018-02-04 20:50:59 +00:00
|
|
|
Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true));
|
2018-02-04 17:19:48 +00:00
|
|
|
//Cache
|
2018-02-04 17:45:01 +00:00
|
|
|
//Artisan::call('config:cache');
|
|
|
|
//Artisan::call('route:cache');
|
2018-01-29 20:14:40 +00:00
|
|
|
}
|
2018-02-06 22:02:50 +00:00
|
|
|
if(is_file(database_path('app.sqlite'))) {
|
2018-02-05 15:22:51 +00:00
|
|
|
if(Schema::hasTable('settings')) {
|
2018-02-05 15:02:18 +00:00
|
|
|
|
2018-02-05 15:22:51 +00:00
|
|
|
// check version to see if an upgrade is needed
|
2018-10-14 15:17:55 +00:00
|
|
|
$db_version = Setting::_fetch('version');
|
2018-02-05 15:22:51 +00:00
|
|
|
$app_version = config('app.version');
|
|
|
|
if(version_compare($app_version, $db_version) == 1) { // app is higher than db, so need to run migrations etc
|
|
|
|
Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true));
|
|
|
|
}
|
2018-11-04 16:20:12 +00:00
|
|
|
|
2018-02-05 15:39:26 +00:00
|
|
|
} else {
|
|
|
|
Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true));
|
|
|
|
}
|
2018-02-07 13:37:40 +00:00
|
|
|
|
2018-02-04 21:28:11 +00:00
|
|
|
}
|
2018-11-04 16:20:12 +00:00
|
|
|
|
|
|
|
$applications = Application::all();
|
|
|
|
if($applications->count() <= 0) {
|
|
|
|
ProcessApps::dispatch();
|
|
|
|
}
|
|
|
|
|
2018-02-12 14:47:12 +00:00
|
|
|
if(!is_file(public_path('storage'))) {
|
|
|
|
Artisan::call('storage:link');
|
2018-10-16 14:44:23 +00:00
|
|
|
\Session::put('current_user', null);
|
2018-02-12 14:47:12 +00:00
|
|
|
}
|
2018-02-04 21:28:11 +00:00
|
|
|
|
2018-10-15 18:56:45 +00:00
|
|
|
// User specific settings need to go here as session isn't available at this point in the app
|
|
|
|
view()->composer('*', function ($view)
|
|
|
|
{
|
2018-10-17 08:41:20 +00:00
|
|
|
|
|
|
|
if(isset($_SERVER['HTTP_AUTHORIZATION']) && !empty($_SERVER['HTTP_AUTHORIZATION'])) {
|
|
|
|
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) =
|
|
|
|
explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
|
|
|
|
}
|
|
|
|
if(!\Auth::check()) {
|
|
|
|
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
|
|
|
|
$credentials = ['username' => $_SERVER['PHP_AUTH_USER'], 'password' => $_SERVER['PHP_AUTH_PW']];
|
|
|
|
|
|
|
|
if (\Auth::attempt($credentials)) {
|
|
|
|
// Authentication passed...
|
|
|
|
$user = \Auth::user();
|
2018-10-17 08:49:23 +00:00
|
|
|
//\Session::put('current_user', $user);
|
|
|
|
session(['current_user' => $user]);
|
2018-10-17 08:41:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 08:49:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
$alt_bg = '';
|
|
|
|
if($bg_image = Setting::fetch('background_image')) {
|
|
|
|
$alt_bg = ' style="background-image: url(/storage/'.$bg_image.')"';
|
|
|
|
}
|
|
|
|
$lang = Setting::fetch('language');
|
|
|
|
\App::setLocale($lang);
|
|
|
|
|
|
|
|
$allusers = User::all();
|
|
|
|
$current_user = User::currentUser();
|
|
|
|
|
|
|
|
$view->with('alt_bg', $alt_bg );
|
|
|
|
$view->with('allusers', $allusers );
|
|
|
|
$view->with('current_user', $current_user );
|
|
|
|
|
2018-10-17 08:41:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-15 18:56:45 +00:00
|
|
|
});
|
|
|
|
|
2018-10-20 23:17:36 +00:00
|
|
|
$this->app['view']->addNamespace('SupportedApps', app_path('SupportedApps'));
|
|
|
|
|
2018-09-30 10:45:08 +00:00
|
|
|
|
|
|
|
if (env('FORCE_HTTPS') === true) {
|
|
|
|
\URL::forceScheme('https');
|
|
|
|
}
|
|
|
|
|
2018-10-15 08:03:54 +00:00
|
|
|
if(env('APP_URL') != 'http://localhost') {
|
|
|
|
\URL::forceRootUrl(env('APP_URL'));
|
|
|
|
}
|
|
|
|
|
2018-01-26 14:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
2018-02-04 20:50:59 +00:00
|
|
|
$this->app->singleton('settings', function () {
|
|
|
|
return new Setting();
|
|
|
|
});
|
2018-01-26 14:35:01 +00:00
|
|
|
}
|
|
|
|
}
|