Merge pull request #64 from Vansers/master

Register form styling and functionally
This commit is contained in:
Nabeel Shahzad
2017-08-12 12:01:08 -05:00
committed by GitHub
11 changed files with 139 additions and 71 deletions

3
.gitignore vendored
View File

@@ -47,3 +47,6 @@ phpvms_next.iml
public/info.php
local.conf.php
# Error Logs
error_log

View File

@@ -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?
}
}

View File

@@ -60,6 +60,10 @@ class User extends Authenticatable
'name',
'email',
'password',
'airline_id',
'home_airport_id',
'curr_airport_id',
'rank_id'
];
/**

View File

@@ -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;
}
}

View File

@@ -0,0 +1,7 @@
@extends('layouts.default.app')
@section('content')
<div class="container registered-page">
<h3>Unauthorized</h3>
<p>Well, this is embarrassing, you are not authorized to access or perform this function. Click <a href="{{ url()->previous() }}">here</a> to go back to the home page.</p>
</div>
@endsection

View File

@@ -0,0 +1,10 @@
@extends('layouts.default.app')
@section('content')
<div class="container registered-page">
<h3>Page Not Found</h3>
<p>Well, this is embarrassing, the page you requested does not exist. Click <a href="{{ url()->previous() }}">here</a> to go back to the home page.
{{ $exception->getMessage() }}
</p>
</div>
@endsection

View File

@@ -50,7 +50,7 @@
</div>
<div class="pull-left">
<h6>
<a href="#pablo" class="link">Create Account</a>
<a href="{{ url('/register') }}" class="link">Create Account</a>
</h6>
</div>
<div class="pull-right">

View File

@@ -2,80 +2,76 @@
@section('content')
<div class="row">
<div class="col-sm-3 push-3"></div>
<div class="col-sm-6">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<form class="form-signin" role="form" method="POST" action="{{ url('/register') }}">
{{ csrf_field() }}
<div class="panel periodic-login">
<div class="panel-body text-center">
{{--<h1 class="atomic-symbol">Mi</h1>--}}
{{--<p class="atomic-mass">14.072110</p>
<p class="element-name">Miminium</p>--}}
<p><img src="assets/frontend/img/logo_login.png" /></p>
{{--<i class="icons icon-arrow-down"></i>--}}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }} form-animate-text" style="margin-top:40px !important;">
<input id="name" type="text" class="form-text" name="name" value="{{ old('name') }}" required autofocus>
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
<span class="bar"></span>
<label for="email" class="col-md-4 control-label">name</label>
<h4>Register</h4>
<label for="name" class="col-md-4 control-label">Full Name</label>
<div class="input-group form-group-no-border{{ $errors->has('name') ? ' has-danger' : '' }}">
<input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" placeholder="Full Name" required>
</div>
@if ($errors->has('name'))
<p class="text-danger">{{ $errors->first('name') }}</p>
@endif
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }} form-animate-text"
style="margin-top:40px !important;">
<input id="email" type="email" class="form-text" name="email" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
<span class="bar"></span>
<label for="email" class="col-md-4 control-label">email</label>
<label for="email" class="col-md-4 control-label">Email Address</label>
<div class="input-group form-group-no-border{{ $errors->has('email') ? ' has-danger' : '' }}">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" placeholder="Email Address" required>
</div>
@if ($errors->has('email'))
<p class="text-danger">{{ $errors->first('email') }}</p>
@endif
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }} form-animate-text" style="margin-top:40px !important;">
<input id="password" type="password" class="form-text" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
<span class="bar"></span>
<label for="email" class="col-md-4 control-label">password</label>
<label for="airline" class="col-md-4 control-label">Airline</label>
<div class="input-group form-group-no-border{{ $errors->has('airline') ? ' has-danger' : '' }}">
<select name="airline" id="airline" class="form-control" required>
@foreach($airlines as $airline)
<option value="{{ $airline->id }}">{{ $airline->code }} - {{ $airline->name }}</option>
@endforeach
</select>
</div>
@if ($errors->has('airline'))
<p class="text-danger">{{ $errors->first('airline') }}</p>
@endif
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }} form-animate-text" style="margin-top:40px !important;">
<input id="password-confirm" type="password" class="form-text" name="password_confirmation" required>
@if ($errors->has('password_confirmation'))
<span class="help-block">
<strong>{{ $errors->first('password_confirmation') }}</strong>
</span>
@endif
<span class="bar"></span>
<label for="email" class="col-md-4 control-label">confirm password</label>
<label for="home_airport" class="col-md-4 control-label">Home Airport</label>
<div class="input-group form-group-no-border{{ $errors->has('home_airport') ? ' has-danger' : '' }}">
<select name="home_airport" id="home_airport" class="form-control" required>
@foreach($airports as $airport)
<option value="{{ $airport->id }}">{{ $airport->icao }} - {{ $airport->name }}</option>
@endforeach
</select>
</div>
@if ($errors->has('home_airport'))
<p class="text-danger">{{ $errors->first('home_airport') }}</p>
@endif
<div class="text-center">
<a href="/login" class="btn btn-primary">Login</a>
<button type="submit" class="btn btn-primary">
Register
</button>
<label for="password" class="col-md-4 control-label">Password</label>
<div class="input-group form-group-no-border{{ $errors->has('password') ? ' has-danger' : '' }}">
<input id="password" type="password" class="form-control" name="password" value="" placeholder="Password" required>
</div>
@if ($errors->has('password'))
<p class="text-danger">{{ $errors->first('password') }}</p>
@endif
<label for="password_confirmation" class="col-md-4 control-label">Confirm Password</label>
<div class="input-group form-group-no-border{{ $errors->has('password_confirmation') ? ' has-danger' : '' }}">
<input id="password_confirmation" type="password" class="form-control" name="password_confirmation" value="" placeholder="Confirm Password" required>
</div>
@if ($errors->has('password_confirmation'))
<p class="text-danger">{{ $errors->first('password_confirmation') }}</p>
@endif
<button type="submit" class="btn btn-primary">Register</button>
</div>
</div>
</form>
</div>
</div>
<div class="col-sm-4"></div>
</div>
@endsection

View File

@@ -0,0 +1,10 @@
@extends('layouts.default.app')
@section('content')
<div class="container registered-page">
<h3>Registration Confirmation</h3>
<p>Your application has been submitted. It requires staff member approval, once a staff member has reviewed your application, you will receive an email confirmation.</p>
</div>
@endsection

View File

@@ -12,7 +12,7 @@ Route::group([
Route::match(['get', 'put'], 'airports/fuel', 'AirportController@fuel');
Route::resource('airports', 'AirportController');
Route::resource('aircraftclasses', 'AircraftClassController');
#Route::resource('aircraftclasses', 'AircraftClassController');
Route::resource('fares', 'FareController');
# subfleet