Add user setup to installer
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\DatabaseService;
|
||||
use DB;
|
||||
|
||||
use App\Console\BaseCommand;
|
||||
@@ -10,9 +11,17 @@ use App\Models\Pirep;
|
||||
|
||||
class DevCommands extends BaseCommand
|
||||
{
|
||||
protected $signature = 'phpvms {cmd}';
|
||||
protected $signature = 'phpvms {cmd} {--file=?}';
|
||||
protected $description = 'Developer commands';
|
||||
|
||||
protected $dbSvc;
|
||||
|
||||
public function __construct(DatabaseService $dbSvc)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbSvc = $dbSvc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run dev related commands
|
||||
*/
|
||||
@@ -28,6 +37,7 @@ class DevCommands extends BaseCommand
|
||||
$commands = [
|
||||
'clear-acars' => 'clearAcars',
|
||||
'compile-assets' => 'compileAssets',
|
||||
'import' => 'importYaml',
|
||||
];
|
||||
|
||||
if(!array_key_exists($command, $commands)) {
|
||||
@@ -66,4 +76,12 @@ class DevCommands extends BaseCommand
|
||||
$this->runCommand('npm update');
|
||||
$this->runCommand('npm run dev');
|
||||
}
|
||||
|
||||
/**
|
||||
* Import data from a YAML file
|
||||
*/
|
||||
protected function importYaml()
|
||||
{
|
||||
$this->info('importing '. $this->argument('file'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class Install extends BaseCommand
|
||||
}
|
||||
|
||||
$this->info('Running database migrations...');
|
||||
$this->call('migrate:refresh');
|
||||
$this->call('migrate');
|
||||
|
||||
# TODO: Call initial seed data, for the groups and other supporting data
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class CreateUsersTable extends Migration
|
||||
$table->string('password');
|
||||
$table->string('api_key', 40)->nullable();
|
||||
$table->unsignedInteger('airline_id');
|
||||
$table->unsignedInteger('rank_id');
|
||||
$table->unsignedInteger('rank_id')->nullable();
|
||||
$table->string('home_airport_id', 5)->nullable();
|
||||
$table->string('curr_airport_id', 5)->nullable();
|
||||
$table->string('last_pirep_id', 12)->nullable();
|
||||
|
||||
@@ -20,7 +20,7 @@ class CreateAirlinesTable extends Migration
|
||||
$table->string('name', 50);
|
||||
$table->string('country', 2)->nullable();
|
||||
$table->string('logo', 255)->nullable();
|
||||
$table->boolean('active');
|
||||
$table->boolean('active')->default(true);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('icao');
|
||||
|
||||
@@ -15,6 +15,7 @@ class CreateAirportsTable extends Migration
|
||||
$table->string('location', 100)->nullable();
|
||||
$table->string('country', 64)->nullable();
|
||||
$table->string('tz', 64)->nullable();
|
||||
$table->boolean('hub')->default(true);
|
||||
$table->unsignedDecimal('fuel_100ll_cost', 19)->default(0);
|
||||
$table->unsignedDecimal('fuel_jeta_cost', 19)->default(0);
|
||||
$table->unsignedDecimal('fuel_mogas_cost', 19)->default(0);
|
||||
|
||||
@@ -3,7 +3,13 @@
|
||||
# want to modify or erase any of this here
|
||||
#
|
||||
|
||||
ranks:
|
||||
- id: 1
|
||||
name: New Pilot
|
||||
hours: 0
|
||||
airports:
|
||||
- id: KAUS
|
||||
iata: AUS
|
||||
icao: KAUS
|
||||
name: Austin-Bergstrom
|
||||
location: Austin, Texas, USA
|
||||
country: United States
|
||||
lat: 30.1945278
|
||||
lon: -97.6698889
|
||||
tz: America/Chicago
|
||||
|
||||
@@ -11,8 +11,7 @@ class UserPending extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
private $subject,
|
||||
$user;
|
||||
public $subject, $user;
|
||||
|
||||
public function __construct(User $user, $subject=null)
|
||||
{
|
||||
|
||||
@@ -12,8 +12,7 @@ class UserRegistered extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
private $subject,
|
||||
$user;
|
||||
public $subject, $user;
|
||||
|
||||
public function __construct(User $user, $subject=null)
|
||||
{
|
||||
|
||||
@@ -11,8 +11,7 @@ class UserRejected extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
private $subject,
|
||||
$user;
|
||||
public $subject, $user;
|
||||
|
||||
public function __construct(User $user, $subject=null)
|
||||
{
|
||||
|
||||
@@ -10,17 +10,12 @@ class Airline extends BaseModel
|
||||
{
|
||||
public $table = 'airlines';
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
public $fillable = [
|
||||
'icao',
|
||||
'iata',
|
||||
'name',
|
||||
'logo',
|
||||
'country',
|
||||
'fuel_100ll_cost',
|
||||
'fuel_jeta_cost',
|
||||
'fuel_mogas_cost',
|
||||
'active',
|
||||
];
|
||||
|
||||
@@ -30,10 +25,7 @@ class Airline extends BaseModel
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'fuel_100ll_cost' => 'double',
|
||||
'fuel_jeta_cost' => 'double',
|
||||
'fuel_mogas_cost' => 'double',
|
||||
'active' => 'integer',
|
||||
'active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,9 @@ class Airport extends BaseModel
|
||||
protected $casts = [
|
||||
'lat' => 'float',
|
||||
'lon' => 'float',
|
||||
'fuel_100ll_cost' => 'float',
|
||||
'fuel_jeta_cost' => 'float',
|
||||
'fuel_mogas_cost' => 'float',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,10 +16,11 @@ class UserService extends BaseService
|
||||
/**
|
||||
* Register a pilot. Also attaches the initial roles
|
||||
* required, and then triggers the UserRegistered event
|
||||
* @param User $user
|
||||
* @param User $user User model
|
||||
* @param array $groups Additional groups to assign
|
||||
* @return mixed
|
||||
*/
|
||||
public function createPilot(User $user)
|
||||
public function createPilot(User $user, array $groups=null)
|
||||
{
|
||||
# Determine if we want to auto accept
|
||||
if(setting('pilot.auto_accept') === true) {
|
||||
@@ -34,6 +35,13 @@ class UserService extends BaseService
|
||||
$role = Role::where('name', 'user')->first();
|
||||
$user->attachRole($role);
|
||||
|
||||
if(!empty($groups) && \is_array($groups)) {
|
||||
foreach ($groups as $group) {
|
||||
$role = Role::where('name', $group)->first();
|
||||
$user->attachRole($role);
|
||||
}
|
||||
}
|
||||
|
||||
# Let's check their rank and where they should start
|
||||
$this->calculatePilotRank($user);
|
||||
|
||||
|
||||
@@ -2,10 +2,16 @@
|
||||
|
||||
namespace Modules\Installer\Http\Controllers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Models\User;
|
||||
use App\Repositories\AirlineRepository;
|
||||
use Log;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
use App\Facades\Utils;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Http\Controllers\AppBaseController;
|
||||
|
||||
use Modules\Installer\Services\DatabaseService;
|
||||
@@ -14,19 +20,26 @@ use Modules\Installer\Services\RequirementsService;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||
|
||||
|
||||
class InstallerController extends AppBaseController
|
||||
{
|
||||
protected $dbService, $envService, $reqService;
|
||||
protected $airlineRepo,
|
||||
$dbService,
|
||||
$envService,
|
||||
$reqService,
|
||||
$userService;
|
||||
|
||||
public function __construct(
|
||||
AirlineRepository $airlineRepo,
|
||||
DatabaseService $dbService,
|
||||
EnvironmentService $envService,
|
||||
RequirementsService $reqService
|
||||
RequirementsService $reqService,
|
||||
UserService $userService
|
||||
) {
|
||||
$this->airlineRepo = $airlineRepo;
|
||||
$this->dbService = $dbService;
|
||||
$this->envService = $envService;
|
||||
$this->reqService = $reqService;
|
||||
$this->userService = $userService;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
@@ -168,14 +181,18 @@ class InstallerController extends AppBaseController
|
||||
*/
|
||||
public function dbsetup(Request $request)
|
||||
{
|
||||
$console_out = '';
|
||||
|
||||
try {
|
||||
$console_out = $this->dbService->setupDB($request->input('db_conn'));
|
||||
$console_out .= $this->dbService->setupDB();
|
||||
} catch(QueryException $e) {
|
||||
flash()->error($e->getMessage());
|
||||
return redirect(route('installer.step2'))->withInput();
|
||||
}
|
||||
|
||||
return view('installer::steps/step2a-completed', [
|
||||
$console_out = trim($console_out);
|
||||
|
||||
return view('installer::steps/step2a-db_output', [
|
||||
'console_output' => $console_out
|
||||
]);
|
||||
}
|
||||
@@ -185,11 +202,72 @@ class InstallerController extends AppBaseController
|
||||
*/
|
||||
public function step3(Request $request)
|
||||
{
|
||||
|
||||
return view('installer::steps/step3-user', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 3 submit
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*/
|
||||
public function usersetup(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'airline_name' => 'required',
|
||||
'airline_icao' => 'required|unique:airlines,icao',
|
||||
'email' => 'required|email|unique:users,email',
|
||||
'password' => 'required|confirmed'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return redirect('install/step3')
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the first airline
|
||||
*/
|
||||
|
||||
$attrs = [
|
||||
'icao' => $request->get('airline_icao'),
|
||||
'name' => $request->get('airline_name'),
|
||||
];
|
||||
|
||||
$airline = $this->airlineRepo->create($attrs);
|
||||
|
||||
/**
|
||||
* Create the user, and associate to the airline
|
||||
* Ensure the seed data at least has one airport
|
||||
* KAUS, for giggles, though.
|
||||
*/
|
||||
|
||||
$attrs = [
|
||||
'name' => $request->get('name'),
|
||||
'email' => $request->get('email'),
|
||||
'api_key' => Utils::generateApiKey(),
|
||||
'airline_id' => $airline->id,
|
||||
'home_airport_id' => 'KAUS',
|
||||
'curr_airport_id' => 'KAUS',
|
||||
'password' => Hash::make($request->get('password'))
|
||||
];
|
||||
|
||||
$user = User::create($attrs);
|
||||
$user = $this->userService->createPilot($user, ['admin']);
|
||||
|
||||
Log::info('User registered: ', $user->toArray());
|
||||
|
||||
return view('installer::steps/step3a-completed', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Final step
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function complete(Request $request)
|
||||
{
|
||||
return redirect('/');
|
||||
return redirect('/login');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,5 +11,6 @@ Route::post('/envsetup', 'InstallerController@envsetup')->name('envsetup');
|
||||
Route::get('/dbsetup', 'InstallerController@dbsetup')->name('dbsetup');
|
||||
|
||||
Route::get('/step3', 'InstallerController@step3')->name('step3');
|
||||
Route::post('/usersetup', 'InstallerController@usersetup')->name('usersetup');
|
||||
|
||||
Route::get('/complete', 'InstallerController@complete')->name('complete');
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
{{--<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>--}}
|
||||
|
||||
<script src="{!! public_asset('/assets/frontend/js/core/jquery.3.2.1.min.js') !!}" type="text/javascript"></script>
|
||||
<script src="{!! public_asset('/assets/system/js/installer-vendor.js') !!}" type="text/javascript"></script>
|
||||
{{--<script src="/assets/frontend/js/core/bootstrap.min.js" type="text/javascript"></script>--}}
|
||||
{{--<script src="/assets/frontend/js/now-ui-kit.js" type="text/javascript"></script>--}}
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
@if($errors->has($field))
|
||||
<p class="text-danger" style="margin-top: 10px;">{!! $errors->first($field); !!}</p>
|
||||
{{--<div class="alert alert-danger" role="alert" style="margin-top: 10px;">
|
||||
{!! $errors->first($field); !!}
|
||||
</div>--}}
|
||||
@endif
|
||||
@@ -1,5 +1,6 @@
|
||||
@extends('installer::app')
|
||||
@section('title', 'Requirements Check')
|
||||
|
||||
@section('content')
|
||||
<div style="align-content: center;">
|
||||
{!! Form::open(['route' => 'installer.step2', 'method' => 'GET']) !!}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
@section('title', 'Database Setup Completed')
|
||||
@section('content')
|
||||
<div style="align-content: center;">
|
||||
{!! Form::open(['route' => 'installer.complete', 'method' => 'GET']) !!}
|
||||
{!! Form::open(['route' => 'installer.step3', 'method' => 'GET']) !!}
|
||||
|
||||
<pre class="lang-sh">
|
||||
<code class="lang-sh">
|
||||
73
modules/Installer/Resources/views/steps/step3-user.blade.php
Normal file
73
modules/Installer/Resources/views/steps/step3-user.blade.php
Normal file
@@ -0,0 +1,73 @@
|
||||
@extends('installer::app')
|
||||
@section('title', 'User Setup')
|
||||
|
||||
@section('content')
|
||||
<div class="row"><div class="col-md-12">
|
||||
<div style="align-content: center;">
|
||||
{!! Form::open(['route' => 'installer.usersetup', 'method' => 'POST']) !!}
|
||||
<table class="table" width="25%">
|
||||
|
||||
<tr>
|
||||
<td colspan="2"><h4>Airline Information</h4></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><p>Airline ICAO</p></td>
|
||||
<td>
|
||||
<div class="form-group">
|
||||
{!! Form::input('text', 'airline_icao', null, ['class' => 'form-control']) !!}
|
||||
@include('installer::flash/check_error', ['field' => 'airline_icao'])
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><p>Airline Name</p></td>
|
||||
<td>
|
||||
<div class="form-group">
|
||||
{!! Form::input('text', 'airline_name', null, ['class' => 'form-control']) !!}
|
||||
@include('installer::flash/check_error', ['field' => 'airline_name'])
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan="2"><h4>First User</h4></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><p>Admin Email</p></td>
|
||||
<td>
|
||||
<div class="form-group">
|
||||
{!! Form::input('text', 'email', null, ['class' => 'form-control']) !!}
|
||||
@include('installer::flash/check_error', ['field' => 'email'])
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><p>Password</p></td>
|
||||
<td>
|
||||
{!! Form::password('password', ['class' => 'form-control']) !!}
|
||||
@include('installer::flash/check_error', ['field' => 'password'])
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><p>Password Confirm</p></td>
|
||||
<td>
|
||||
{!! Form::password('password_confirmation', ['class' => 'form-control']) !!}
|
||||
@include('installer::flash/check_error', ['field' => 'password_confirmation'])
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<div id="dbtest"></div>
|
||||
<p style="text-align: right">
|
||||
{!! Form::submit('Complete Setup >>', ['class' => 'btn btn-success']) !!}
|
||||
</p>
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -0,0 +1,19 @@
|
||||
@extends('installer::app')
|
||||
@section('title', 'Installation Completed!')
|
||||
|
||||
@section('content')
|
||||
<div style="align-content: center;">
|
||||
{!! Form::open(['route' => 'installer.complete', 'method' => 'GET']) !!}
|
||||
|
||||
<h4>Install Completed!</h4>
|
||||
|
||||
<p>Click the button to proceed to the login screen!</p>
|
||||
|
||||
<p style="text-align: right">
|
||||
{!! Form::submit('Install Complete! Continue to Log-In >>',
|
||||
['class' => 'btn btn-success'])
|
||||
!!}
|
||||
</p>
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
@endsection
|
||||
@@ -42,14 +42,12 @@ class DatabaseService {
|
||||
/**
|
||||
* Setup the database by running the migration commands
|
||||
*/
|
||||
public function setupDB($db_driver='')
|
||||
public function setupDB()
|
||||
{
|
||||
$output = '';
|
||||
|
||||
if($db_driver === 'sqlite') {
|
||||
\Artisan::call('database:create');
|
||||
$output .= \Artisan::output();
|
||||
}
|
||||
\Artisan::call('database:create');
|
||||
$output .= \Artisan::output();
|
||||
|
||||
\Artisan::call('migrate');
|
||||
$output .= trim(\Artisan::output());
|
||||
|
||||
28123
public/assets/system/js/installer-vendor.js
Normal file
28123
public/assets/system/js/installer-vendor.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,5 +4,6 @@
|
||||
"/assets/admin/css/vendor.min.css": "/assets/admin/css/vendor.min.css?id=152f2c5d0bcfff37513a",
|
||||
"/assets/admin/js/vendor.js": "/assets/admin/js/vendor.js?id=aa3c49b31b83782ed27d",
|
||||
"/assets/system/js/vendor.js": "/assets/system/js/vendor.js?id=022e73793e29fb2c6825",
|
||||
"/assets/system/css/vendor.css": "/assets/system/css/vendor.css?id=7bd98a28084fea99e307"
|
||||
"/assets/system/css/vendor.css": "/assets/system/css/vendor.css?id=7bd98a28084fea99e307",
|
||||
"/assets/system/js/installer-vendor.js": "/assets/system/js/installer-vendor.js?id=b2bca761f222e97bf4ff"
|
||||
}
|
||||
@@ -85,6 +85,17 @@ mix.styles([
|
||||
.sourceMaps();
|
||||
|
||||
|
||||
/**
|
||||
* INSTALLER VENDOR FILES
|
||||
*/
|
||||
|
||||
mix.scripts([
|
||||
'node_modules/lodash/lodash.js',
|
||||
'node_modules/jquery/dist/jquery.js',
|
||||
'node_modules/pjax/pjax.js',
|
||||
], 'public/assets/system/js/installer-vendor.js');
|
||||
|
||||
|
||||
/**
|
||||
* DEFAULT SKIN FRONTEND FILES
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user