Rename PilotState class to UserState
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
];
|
||||
}
|
||||
23
app/Models/Enums/UserState.php
Normal file
23
app/Models/Enums/UserState.php
Normal 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',
|
||||
];
|
||||
}
|
||||
@@ -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')) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user