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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user