diff --git a/.gitignore b/.gitignore index f2387b64..77f4a6ed 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ phpvms_next.iml public/info.php local.conf.php + +# Error Logs +error_log diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index d97f0278..f66bc995 100755 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -3,10 +3,12 @@ namespace App\Http\Controllers\Auth; use Validator; -use App\Models\Role; -use App\Models\User; +use App\Models\Airport; +use App\Models\Airline; +use App\Services\PilotService; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\RegistersUsers; +use Illuminate\Http\Request; class RegisterController extends Controller { @@ -32,7 +34,12 @@ class RegisterController extends Controller public function showRegistrationForm() { - return $this->view('auth.register'); + $airports = Airport::all(); + $airlines = Airline::all(); + return $this->view('auth.register', [ + 'airports' => $airports, + 'airlines' => $airlines, + ]); } /** @@ -56,26 +63,38 @@ class RegisterController extends Controller return Validator::make($data, [ 'name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', + 'airline' => 'required', + 'home_airport' => 'required', 'password' => 'required|min:5|confirmed', ]); } /** - * Create a new user instance after a valid registration. + * Get a validator for an incoming registration request. * * @param array $data - * @return User + * @return \Illuminate\Contracts\Validation\Validator */ protected function create(array $data) { - $user = User::create([ - 'name' => $data['name'], - 'email' => $data['email'], - 'password' => bcrypt($data['password']), + # First, validate the posted data + $this->validate(request(), [ + 'name' => 'required', + 'email' => 'required|email', + 'airline' => 'required', + 'home_airport' => 'required', + 'password' => 'required|confirmed' ]); - $role = Role::where('name', 'admin')->first(); - $user->attachRole($role); - return $user->refresh(); + # Let's call the service + $pilotService = app('App\Services\PilotService'); + + # Let's tell the service to create the pilot + if($pilotService->createPilot($data)) + { + return $this->view('auth.registered'); + } + + # I'm not sure if we really need to add the error something if createPilot fails? } } diff --git a/app/Models/User.php b/app/Models/User.php index cf09ed56..c322a448 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -60,6 +60,10 @@ class User extends Authenticatable 'name', 'email', 'password', + 'airline_id', + 'home_airport_id', + 'curr_airport_id', + 'rank_id' ]; /** diff --git a/app/Models/UuidTrait.php b/app/Models/Uuids.php similarity index 100% rename from app/Models/UuidTrait.php rename to app/Models/Uuids.php diff --git a/app/Services/PilotService.php b/app/Services/PilotService.php index 336151a7..8760dac9 100644 --- a/app/Services/PilotService.php +++ b/app/Services/PilotService.php @@ -4,9 +4,9 @@ namespace App\Services; use App\Models\User; use App\Models\Rank; +use App\Models\Role; use Illuminate\Support\Facades\Cache; - - +use Illuminate\Support\Facades\Hash; class PilotService extends BaseService { @@ -55,4 +55,23 @@ class PilotService extends BaseService return $pilot; } + public function createPilot(array $data) + { + $user = User::create(['name' => $data['name'], + 'email' => $data['email'], + '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 + + # Looking good, let's return their information + return $user; + } + } diff --git a/resources/views/errors/401.blade.php b/resources/views/errors/401.blade.php new file mode 100644 index 00000000..d4ce8c52 --- /dev/null +++ b/resources/views/errors/401.blade.php @@ -0,0 +1,7 @@ +@extends('layouts.default.app') +@section('content') +
+

Unauthorized

+

Well, this is embarrassing, you are not authorized to access or perform this function. Click here to go back to the home page.

+
+@endsection \ No newline at end of file diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php new file mode 100644 index 00000000..93af0456 --- /dev/null +++ b/resources/views/errors/404.blade.php @@ -0,0 +1,10 @@ +@extends('layouts.default.app') +@section('content') +
+

Page Not Found

+

Well, this is embarrassing, the page you requested does not exist. Click here to go back to the home page. + +{{ $exception->getMessage() }} +

+
+@endsection diff --git a/resources/views/layouts/default/auth/login.blade.php b/resources/views/layouts/default/auth/login.blade.php index 060e7141..f33891b7 100644 --- a/resources/views/layouts/default/auth/login.blade.php +++ b/resources/views/layouts/default/auth/login.blade.php @@ -50,7 +50,7 @@
- Create Account + Create Account
diff --git a/resources/views/layouts/default/auth/register.blade.php b/resources/views/layouts/default/auth/register.blade.php index dacbd256..0a854264 100644 --- a/resources/views/layouts/default/auth/register.blade.php +++ b/resources/views/layouts/default/auth/register.blade.php @@ -2,80 +2,76 @@ @section('content')
-
-
+
+