Add explicit pilot states

This commit is contained in:
Nabeel Shahzad
2017-12-14 23:51:57 -06:00
parent 4fb66b5118
commit aed09c2bf5
5 changed files with 57 additions and 31 deletions

View File

@@ -87,6 +87,15 @@ class CreateSettingsTable extends Migration
],
[
'order' => 31,
'name' => 'Auto Accept New Pilot',
'group' => 'pilots',
'key' => 'pilot.auto_accept',
'value' => true,
'type' => 'boolean',
'description' => 'Automatically accept a pilot when they register',
],
[
'order' => 32,
'name' => 'Pilot ID Length',
'group' => 'pilots',
'key' => 'pilots.id_length',

View File

@@ -28,6 +28,7 @@ class CreateUsersTable extends Migration
$table->unsignedBigInteger('flight_time')->default(0);
$table->decimal('balance', 19)->nullable();
$table->string('timezone', 64)->nullable();
$table->unsignedTinyInteger('status')->default(0);
$table->boolean('active')->nullable();
$table->rememberToken();
$table->timestamps();

View File

@@ -16,6 +16,45 @@ use Illuminate\Support\Facades\Hash;
class UserService extends BaseService
{
/**
* Register a pilot
* @param array $data
* @return mixed
*/
public function createPilot(array $data)
{
$opts = [
'name' => $data['name'],
'email' => $data['email'],
'api_key' => Utils::generateApiKey(),
'airline_id' => $data['airline'],
'home_airport_id' => $data['home_airport'],
'curr_airport_id' => $data['home_airport'],
'password' => Hash::make($data['password'])
];
# Determine if we want to auto accept
if(setting('pilot.auto_accept') === true) {
$opts['status'] = config('enums.states.ACTIVE');
} else {
$opts['status'] = config('enums.states.PENDING');
}
$user = User::create($opts);
# Attach the user roles
$role = Role::where('name', 'user')->first();
$user->attachRole($role);
# Let's check their rank
$this->calculatePilotRank($user);
# TODO: Send out an email
event(new UserRegistered($user));
return $user;
}
public function adjustFlightCount(User $user, int $count): User
{
$user->refresh();
@@ -60,34 +99,4 @@ class UserService extends BaseService
return $user;
}
/**
* Register a pilot
* @param array $data
* @return mixed
*/
public function createPilot(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'api_key' => Utils::generateApiKey(),
'airline_id' => $data['airline'],
'home_airport_id' => $data['home_airport'],
'curr_airport_id' => $data['home_airport'],
'password' => Hash::make($data['password'])
]);
# Attach the user roles
$role = Role::where('name', 'user')->first();
$user->attachRole($role);
# Let's check their rank
$this->calculatePilotRank($user);
# TODO: Send out an email
event(new UserRegistered($user));
return $user;
}
}