diff --git a/app/Database/seeds/dev.yml b/app/Database/seeds/dev.yml index 73b4f429..5c344722 100644 --- a/app/Database/seeds/dev.yml +++ b/app/Database/seeds/dev.yml @@ -22,7 +22,7 @@ users: flight_time: 43200 created_at: now updated_at: now - active: 1 + state: 1 - id: 2 name: Carla Walters email: carla.walters68@example.com @@ -36,7 +36,7 @@ users: flight_time: 43200 created_at: now updated_at: now - active: 1 + state: 0 - id: 3 name: Raymond Pearson email: raymond.pearson56@example.com @@ -50,7 +50,7 @@ users: flight_time: 43200 created_at: now updated_at: now - active: 0 + state: 1 role_user: - user_id: 1 diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 63a01e03..762af262 100755 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -2,8 +2,13 @@ namespace App\Http\Controllers\Auth; -use App\Http\Controllers\Controller; +use Illuminate\Http\Request; use Illuminate\Foundation\Auth\AuthenticatesUsers; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Log; + +use App\Http\Controllers\Controller; +use App\Models\Enums\PilotState; class LoginController extends Controller { @@ -20,4 +25,32 @@ class LoginController extends Controller { return $this->view('auth/login'); } + + protected function sendLoginResponse(Request $request) + { + $request->session()->regenerate(); + $this->clearLoginAttempts($request); + + $user = Auth::user(); + + // TODO: How to handle ON_LEAVE? + if($user->state !== PilotState::ACTIVE) { + + // Log them out + $this->guard()->logout(); + $request->session()->invalidate(); + + // Redirect to one of the error pages + if($user->state === PilotState::PENDING) { + return $this->view('auth.pending'); + } + + elseif ($user->state === PilotState::REJECTED) { + return $this->view('auth.rejected'); + } + } + + return $this->authenticated($request, $this->guard()->user()) + ?: redirect()->intended($this->redirectPath()); + } } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 1b32b873..68ada101 100755 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -2,6 +2,8 @@ namespace App\Http\Controllers\Auth; +use App\Models\Enums\PilotState; +use Log; use App\Facades\Utils; use App\Models\User; use Illuminate\Support\Facades\Hash; @@ -70,14 +72,6 @@ class RegisterController extends Controller */ protected function create(array $data) { - $this->validate(request(), [ - 'name' => 'required', - 'email' => 'required|email', - 'airline' => 'required', - 'home_airport' => 'required', - 'password' => 'required|confirmed' - ]); - $opts = [ 'name' => $data['name'], 'email' => $data['email'], @@ -91,6 +85,32 @@ class RegisterController extends Controller $user = User::create($opts); $user = $this->userService->createPilot($user); + Log::info('User registered: ', $user->toArray()); + return $user; } + + /** + * Handle a registration request for the application. + * @throws \RuntimeException + */ + public function register(Request $request) + { + $this->validate(request(), [ + 'name' => 'required', + 'email' => 'required|unique:users|email', + 'airline' => 'required', + 'home_airport' => 'required', + 'password' => 'required|confirmed' + ]); + + $user = $this->create($request->all()); + + if($user->state === PilotState::PENDING) { + return $this->view('auth.pending'); + } + + $this->guard()->login($user); + return redirect('/dashboard'); + } } diff --git a/app/Models/Enums/PilotState.php b/app/Models/Enums/PilotState.php index 1663e925..cef812ac 100644 --- a/app/Models/Enums/PilotState.php +++ b/app/Models/Enums/PilotState.php @@ -11,14 +11,16 @@ namespace App\Models\Enums; class PilotState extends EnumBase { - const PENDING = 1; - const ACTIVE = 2; + 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', ]; diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 5c758b25..a2f09a41 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -25,11 +25,11 @@ class UserService extends BaseService public function createPilot(User $user) { # Determine if we want to auto accept - if(setting('pilot.auto_accept') === true) { + /*if(setting('pilot.auto_accept') === true) { $user->state = PilotState::ACTIVE; } else { $user->state = PilotState::PENDING; - } + }*/ $user->save(); diff --git a/public/assets/frontend/css/styles.css b/public/assets/frontend/css/styles.css index 8cc782cb..0508723a 100644 --- a/public/assets/frontend/css/styles.css +++ b/public/assets/frontend/css/styles.css @@ -20,3 +20,21 @@ .border-blue-bottom { border-bottom: 3px solid #067ec1; } + +.full-height { + height: 50vh; +} + +.flex-center { + align-items: center; + display: flex; + justify-content: center; +} + +.position-ref { + position: relative; +} + +.m-b-md { + margin-bottom: 30px; +} diff --git a/resources/views/layouts/default/auth/pending.blade.php b/resources/views/layouts/default/auth/pending.blade.php new file mode 100644 index 00000000..533f6929 --- /dev/null +++ b/resources/views/layouts/default/auth/pending.blade.php @@ -0,0 +1,14 @@ +@extends('layouts.default.app') + +@section('title', 'registration pending') +@section('content') +