Add user setup to installer
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user