Rename PilotState class to UserState

This commit is contained in:
Nabeel Shahzad 2017-12-30 20:40:32 -06:00
parent 778780f3f2
commit 81e82629ac
13 changed files with 56 additions and 60 deletions

View File

@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;
use App\Models\Enums\PilotState;
use App\Models\Enums\UserState;
class LoginController extends Controller
{
@ -35,21 +35,21 @@ class LoginController extends Controller
$user = Auth::user();
// TODO: How to handle ON_LEAVE?
if($user->state !== PilotState::ACTIVE) {
if($user->state !== UserState::ACTIVE) {
Log::info('Trying to login '. $user->pilot_id .', state '
. PilotState::label($user->state));
. UserState::label($user->state));
// Log them out
$this->guard()->logout();
$request->session()->invalidate();
// Redirect to one of the error pages
if($user->state === PilotState::PENDING) {
if($user->state === UserState::PENDING) {
return $this->view('auth.pending');
} elseif ($user->state === PilotState::REJECTED) {
} elseif ($user->state === UserState::REJECTED) {
return $this->view('auth.rejected');
} elseif ($user->state === PilotState::SUSPENDED) {
} elseif ($user->state === UserState::SUSPENDED) {
return $this->view('auth.suspended');
}
}

View File

@ -14,7 +14,7 @@ use App\Facades\Utils;
use App\Models\Airport;
use App\Models\Airline;
use App\Services\UserService;
use App\Models\Enums\PilotState;
use App\Models\Enums\UserState;
use App\Http\Controllers\Controller;
use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
@ -118,7 +118,7 @@ class RegisterController extends Controller
$user = $this->create($request->all());
if($user->state === PilotState::PENDING) {
if($user->state === UserState::PENDING) {
return $this->view('auth.pending');
}

View File

@ -5,7 +5,7 @@ namespace App\Listeners;
use Log;
use Illuminate\Support\Facades\Mail;
use App\Models\Enums\PilotState;
use App\Models\Enums\UserState;
/**
* Handle sending emails on different events
@ -34,7 +34,7 @@ class NotificationEventListener
{
Log::info('onUserRegister: '
. $event->user->pilot_id . ' is '
. PilotState::label($event->user->state)
. UserState::label($event->user->state)
. ', sending active email');
# First send the admin a notification
@ -45,14 +45,14 @@ class NotificationEventListener
}
# Then notify the user
if($event->user->state === PilotState::ACTIVE) {
if($event->user->state === UserState::ACTIVE) {
$email = new \App\Mail\UserRegistered(
$event->user,
'Welcome to ' . config('app.name') . '!'
);
Mail::to($event->user->email)->send($email);
} else if($event->user->state === PilotState::PENDING) {
} else if($event->user->state === UserState::PENDING) {
Mail::to($event->user->email)->send(new \App\Mail\UserPending($event->user));
}
}
@ -63,8 +63,8 @@ class NotificationEventListener
*/
public function onUserStateChange(UserStateChanged $event)
{
if ($event->old_state === PilotState::PENDING) {
if ($event->user->state === PilotState::ACTIVE)
if ($event->old_state === UserState::PENDING) {
if ($event->user->state === UserState::ACTIVE)
{
$email = new \App\Mail\UserRegistered(
$event->user,
@ -74,7 +74,7 @@ class NotificationEventListener
Mail::to($event->user->email)->send($email);
}
else if ($event->user->state === PilotState::REJECTED)
else if ($event->user->state === UserState::REJECTED)
{
$email = new \App\Mail\UserRejected($event->user);
Mail::to($event->user->email)->send($email);
@ -82,7 +82,7 @@ class NotificationEventListener
}
# TODO: Other state transitions
elseif ($event->old_state === PilotState::ACTIVE)
elseif ($event->old_state === UserState::ACTIVE)
{
}

View File

@ -1,27 +0,0 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: nabeelshahzad
* Date: 12/22/17
* Time: 12:14 PM
*/
namespace App\Models\Enums;
class PilotState extends EnumBase
{
const PENDING = 0;
const ACTIVE = 1;
const REJECTED = 2;
const ON_LEAVE = 3;
const SUSPENDED = 4;
protected static $labels = [
PilotState::PENDING => 'Pending',
PilotState::ACTIVE => 'Active',
PilotState::REJECTED => 'Rejected',
PilotState::ON_LEAVE => 'On Leave',
PilotState::SUSPENDED => 'Suspended',
];
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Hold the user states
*/
namespace App\Models\Enums;
class UserState extends EnumBase
{
const PENDING = 0;
const ACTIVE = 1;
const REJECTED = 2;
const ON_LEAVE = 3;
const SUSPENDED = 4;
protected static $labels = [
UserState::PENDING => 'Pending',
UserState::ACTIVE => 'Active',
UserState::REJECTED => 'Rejected',
UserState::ON_LEAVE => 'On Leave',
UserState::SUSPENDED => 'Suspended',
];
}

View File

@ -4,7 +4,7 @@ namespace App\Repositories;
use Illuminate\Http\Request;
use App\Models\User;
use App\Models\Enums\PilotState;
use App\Models\Enums\UserState;
use App\Repositories\Criteria\WhereCriteria;
class UserRepository extends BaseRepository
@ -29,7 +29,7 @@ class UserRepository extends BaseRepository
public function getPendingCount()
{
$where = [
'state' => PilotState::PENDING,
'state' => UserState::PENDING,
];
$users = $this->orderBy('created_at', 'desc')->findWhere($where)->count();
@ -48,7 +48,7 @@ class UserRepository extends BaseRepository
$where = [];
if($only_active) {
$where['state'] = PilotState::ACTIVE;
$where['state'] = UserState::ACTIVE;
}
if ($request->filled('name')) {

View File

@ -9,7 +9,7 @@ use App\Models\Role;
use App\Events\UserRegistered;
use App\Events\UserStateChanged;
use App\Events\UserStatsChanged;
use App\Models\Enums\PilotState;
use App\Models\Enums\UserState;
class UserService extends BaseService
{
@ -24,9 +24,9 @@ class UserService extends BaseService
{
# Determine if we want to auto accept
if(setting('pilot.auto_accept') === true) {
$user->state = PilotState::ACTIVE;
$user->state = UserState::ACTIVE;
} else {
$user->state = PilotState::PENDING;
$user->state = UserState::PENDING;
}
$user->save();
@ -66,8 +66,8 @@ class UserService extends BaseService
}
Log::info('User ' . $user->pilot_id . ' state changing from '
. PilotState::label($old_state) . ' to '
. PilotState::label($user->state));
. UserState::label($old_state) . ' to '
. UserState::label($user->state));
event(new UserStateChanged($user, $old_state));
}

View File

@ -118,7 +118,7 @@ return [
'Yaml' => Symfony\Component\Yaml\Yaml::class,
# ENUMS
'PilotState' => App\Models\Enums\PilotState::class,
'UserState' => App\Models\Enums\UserState::class,
'PirepSource' => App\Models\Enums\PirepSource::class,
'PirepState' => App\Models\Enums\PirepState::class,
'PirepStatus' => App\Models\Enums\PirepStatus::class,

View File

@ -52,7 +52,7 @@
<div class="form-group col-sm-6">
{!! Form::label('state', 'State:') !!}
<label class="checkbox-inline">
{!! Form::select('state', PilotState::labels(), null, ['class' => 'form-control select2']) !!}
{!! Form::select('state', UserState::labels(), null, ['class' => 'form-control select2']) !!}
</label>
</div>

View File

@ -3,7 +3,7 @@
@section('title', 'Users')
@section('actions')
<li><a href="{!! route('admin.users.index') !!}?search=state:0">
<i class="ti-user"></i>{!! PilotState::label(PilotState::PENDING) !!}</a>
<i class="ti-user"></i>{!! UserState::label(UserState::PENDING) !!}</a>
</li>
@endsection

View File

@ -13,14 +13,14 @@
<td>{!! $user->email !!}</td>
<td>{!! show_date($user->created_at) !!}</td>
<td class="text-center">
@if($user->state == PilotState::ACTIVE)
@if($user->state == UserState::ACTIVE)
<span class="label label-success">
@elseif($user->state == PilotState::PENDING)
@elseif($user->state == UserState::PENDING)
<span class="label label-warning">
@else
<span class="label label-default">
@endif
{!! PilotState::label($user->state) !!}</span>
{!! UserState::label($user->state) !!}</span>
</td>
<td class="text-right">
{!! Form::open(['route' => ['admin.users.destroy', $user->id], 'method' => 'delete']) !!}

View File

@ -3,7 +3,7 @@ A new user has signed up!
Name: {!! $user->name !!}!
Email: {!! $user->email !!}
State: {!! PilotState::label($user->state) !!}
State: {!! UserState::label($user->state) !!}
{{ config('app.name') }}
@endcomponent

View File

@ -2,7 +2,7 @@
use Illuminate\Support\Facades\Mail;
use \App\Models\Enums\PilotState;
use \App\Models\Enums\UserState;
class RegistrationTest extends TestCase
{
@ -23,7 +23,7 @@ class RegistrationTest extends TestCase
$user = factory(App\Models\User::class)->create();
$user = $userSvc->createPilot($user);
$this->assertEquals(PilotState::ACTIVE, $user->state);
$this->assertEquals(UserState::ACTIVE, $user->state);
Event::assertDispatched(\App\Events\UserRegistered::class, function ($e) use ($user) {
return $e->user->id === $user->id