update profile/change password and profile cosmetic changes
This commit is contained in:
parent
84f6c58cb9
commit
0bb2dabb8c
@ -110,7 +110,7 @@ class RegisterController extends Controller
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'name' => 'required',
|
||||
'email' => 'required|unique:users|email',
|
||||
'email' => 'required|email|unique:users,email',
|
||||
'airline_id' => 'required',
|
||||
'home_airport_id' => 'required',
|
||||
'password' => 'required|confirmed'
|
||||
|
@ -2,24 +2,39 @@
|
||||
|
||||
namespace App\Http\Controllers\Frontend;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Repositories\AirportRepository;
|
||||
use App\Http\Controllers\AppBaseController;
|
||||
use Log;
|
||||
use Hash;
|
||||
use Flash;
|
||||
use Validator;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Jackiedo\Timezonelist\Facades\Timezonelist;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Repositories\AirlineRepository;
|
||||
use App\Repositories\AirportRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
use App\Http\Controllers\AppBaseController;
|
||||
|
||||
class ProfileController extends AppBaseController
|
||||
{
|
||||
private $airportRepository;
|
||||
private $airlineRepo,
|
||||
$airportRepo,
|
||||
$userRepo;
|
||||
|
||||
public function __construct(AirportRepository $airportRepo)
|
||||
{
|
||||
$this->airportRepository = $airportRepo;
|
||||
public function __construct(
|
||||
AirlineRepository $airlineRepo,
|
||||
AirportRepository $airportRepo,
|
||||
UserRepository $userRepo
|
||||
) {
|
||||
$this->airlineRepo = $airlineRepo;
|
||||
$this->airportRepo = $airportRepo;
|
||||
$this->userRepo = $userRepo;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$airports = $this->airportRepository->all();
|
||||
$airports = $this->airportRepo->all();
|
||||
|
||||
return $this->view('profile.index', [
|
||||
'user' => Auth::user(),
|
||||
@ -35,7 +50,7 @@ class ProfileController extends AppBaseController
|
||||
return redirect(route('frontend.dashboard.index'));
|
||||
}
|
||||
|
||||
$airports = $this->airportRepository->all();
|
||||
$airports = $this->airportRepo->all();
|
||||
|
||||
return $this->view('profile.index', [
|
||||
'user' => $user,
|
||||
@ -43,8 +58,59 @@ class ProfileController extends AppBaseController
|
||||
]);
|
||||
}
|
||||
|
||||
public function update()
|
||||
/**
|
||||
* Show the edit for form the user's profile
|
||||
*/
|
||||
public function edit(Request $request)
|
||||
{
|
||||
$user = User::where('id', Auth::user()->id)->first();
|
||||
if (empty($user)) {
|
||||
Flash::error('User not found!');
|
||||
return redirect(route('frontend.dashboard.index'));
|
||||
}
|
||||
|
||||
$airlines = $this->airlineRepo->selectBoxList();
|
||||
$airports = $this->airportRepo->selectBoxList();
|
||||
|
||||
return $this->view('profile.edit', [
|
||||
'user' => $user,
|
||||
'airlines' => $airlines,
|
||||
'airports' => $airports,
|
||||
'timezones' => Timezonelist::toArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$id = Auth::user()->id;
|
||||
$user = $this->userRepo->findWithoutFail($id);
|
||||
|
||||
$validator = Validator::make($request->toArray(), [
|
||||
'name' => 'required',
|
||||
'email' => 'required|unique:users,email,'.$id,
|
||||
'airline_id' => 'required',
|
||||
'password' => 'confirmed'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
Log::info('validator failed for user '.$user->pilot_id);
|
||||
Log::info($validator->errors()->toArray());
|
||||
|
||||
return redirect(route('frontend.profile.edit', $id))
|
||||
->withErrors($validator)
|
||||
->withInput();
|
||||
}
|
||||
|
||||
$req_data = $request->all();
|
||||
if (!$request->filled('password')) {
|
||||
unset($req_data['password']);
|
||||
} else {
|
||||
$req_data['password'] = Hash::make($req_data['password']);
|
||||
}
|
||||
|
||||
$user = $this->userRepo->update($req_data, $id);
|
||||
|
||||
Flash::success('Profile updated successfully!');
|
||||
return redirect(route('frontend.profile.index'));
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel="apple-touch-icon" sizes="76x76" href="/assets/frontend/img/apple-icon.png">
|
||||
<link rel="icon" type="image/png" href="/assets/frontend/img/favicon.png">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||
<title>@yield('title') - {!! config('app.name') !!}</title>
|
||||
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no'
|
||||
|
13
resources/views/layouts/default/profile/edit.blade.php
Normal file
13
resources/views/layouts/default/profile/edit.blade.php
Normal file
@ -0,0 +1,13 @@
|
||||
@extends('layouts.default.app')
|
||||
@section('title', 'edit profile')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h2 class="description">edit your profile</h2>
|
||||
@include('flash::message')
|
||||
{!! Form::model($user, ['route' => ['frontend.profile.update', $user->id], 'method' => 'patch']) !!}
|
||||
@include('layouts.default.profile.fields')
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
@ -1,23 +1,78 @@
|
||||
<div class="section-story-overview">
|
||||
<div class="row">
|
||||
<div class="col-md-9 push-md-1">
|
||||
<p class="category">Update</p>
|
||||
{!! Form::model($user, ['url' => url('/profile'), 'method' => 'post']) !!}
|
||||
<div class="card">
|
||||
<div class="card-block">
|
||||
<div class="input-group form-group-no-border{{ $errors->has('email') ? ' has-error' : '' }} input-lg">
|
||||
<span class="input-group-addon">
|
||||
<i class="fa fa-envelope-open-o" aria-hidden="true"></i>
|
||||
</span>
|
||||
{!! Form::email('email', null, [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Email',
|
||||
]) !!}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td>
|
||||
<div class="input-group form-group-no-border{{ $errors->has('name') ? ' has-danger' : '' }}">
|
||||
{!! Form::text('name', null, ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
@if ($errors->has('name'))
|
||||
<p class="text-danger">{{ $errors->first('name') }}</p>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
<tr>
|
||||
<td>Email</td>
|
||||
<td>
|
||||
<div class="input-group form-group-no-border{{ $errors->has('email') ? ' has-danger' : '' }}">
|
||||
{!! Form::text('email', null, ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
@if ($errors->has('email'))
|
||||
<p class="text-danger">{{ $errors->first('email') }}</p>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Airline</td>
|
||||
<td>
|
||||
<div class="input-group form-group-no-border{{ $errors->has('airline') ? ' has-danger' : '' }}">
|
||||
{!! Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) !!}
|
||||
</div>
|
||||
@if ($errors->has('airline_id'))
|
||||
<p class="text-danger">{{ $errors->first('airline_id') }}</p>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Timezone</td>
|
||||
<td>
|
||||
<div class="input-group form-group-no-border{{ $errors->has('timezone') ? ' has-danger' : '' }}">
|
||||
{!! Form::select('timezone', $timezones, null, ['class' => 'form-control select2' ]); !!}
|
||||
</div>
|
||||
@if ($errors->has('timezone'))
|
||||
<p class="text-danger">{{ $errors->first('timezone') }}</p>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Change Password</td>
|
||||
<td>
|
||||
<div class="input-group form-group-no-border{{ $errors->has('password') ? ' has-danger' : '' }}">
|
||||
{!! Form::password('password', ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
@if ($errors->has('password'))
|
||||
<p class="text-danger">{{ $errors->first('password') }}</p>
|
||||
@endif
|
||||
|
||||
<p>Confirm Password:</p>
|
||||
<div class="input-group form-group-no-border{{ $errors->has('password_confirmation') ? ' has-danger' : '' }}">
|
||||
{!! Form::password('password_confirmation', ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
@if ($errors->has('password_confirmation'))
|
||||
<p class="text-danger">{{ $errors->first('password_confirmation') }}</p>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<div style="width: 100%; text-align: right; padding-top: 20px;">
|
||||
{!! Form::submit('Update Profile', ['class' => 'btn btn-primary']) !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,49 +1,115 @@
|
||||
@extends('layouts.default.app')
|
||||
@section('title', 'profile')
|
||||
@section('content')
|
||||
<div class="container profile-page">
|
||||
<div class="page-header page-header-small text-color-dark-beige">
|
||||
<div class="page-header-image"></div>
|
||||
<div class="container text-color-dark-beige">
|
||||
<div class="content-center" style="color: #9b9992;">
|
||||
<div class="photo-container">
|
||||
<img src="/assets/frontend/img/logo.svg" alt="">
|
||||
</div>
|
||||
<h3 class="title">{!! $user->name !!}</h3>
|
||||
<h6>{!! $user->rank->name !!}</h6>
|
||||
<p class="description" style="color: #9A9A9A;">
|
||||
{!! $user->airline->name !!}
|
||||
</p
|
||||
<br /><br />
|
||||
<div class="content" style="max-width: 650px;">
|
||||
|
||||
<div class="social-description">
|
||||
<h2>{!! $user->flights!!}</h2>
|
||||
<p>Flights</p>
|
||||
</div>
|
||||
|
||||
<div class="social-description">
|
||||
<h2>{!! \App\Facades\Utils::secondsToTimeString($user->flight_time, false)!!}</h2>
|
||||
<p>Flight Hours</p>
|
||||
</div>
|
||||
|
||||
@if($user->home_airport)
|
||||
<div class="social-description">
|
||||
<h2>{!! $user->home_airport->icao !!}</h2>
|
||||
<p>Home Airport</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if($user->current_airport)
|
||||
<div class="social-description">
|
||||
<h2>{!! $user->current_airport->icao !!}</h2>
|
||||
<p>Current Airport</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row profile-page content-center text-color-dark-beige">
|
||||
<div class="col-md-4" style="text-align:center;">
|
||||
<div class="photo-container">
|
||||
<img src="{!! public_asset('/assets/frontend/img/logo.svg') !!}" alt="">
|
||||
</div>
|
||||
<h3 class="title">{!! $user->name !!}</h3>
|
||||
<h6>{!! $user->pilot_id !!}</h6>
|
||||
<h6>{!! $user->rank->name !!}</h6>
|
||||
<p class="description" style="color: #9A9A9A;">
|
||||
{!! $user->airline->name !!}
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-8 content-center">
|
||||
<div class="content">
|
||||
<div class="social-description">
|
||||
<h2>{!! $user->flights!!}</h2>
|
||||
<p>Flights</p>
|
||||
</div>
|
||||
|
||||
<div class="social-description">
|
||||
<h2>{!! \App\Facades\Utils::secondsToTimeString($user->flight_time, false)!!}</h2>
|
||||
<p>Flight Hours</p>
|
||||
</div>
|
||||
|
||||
@if($user->home_airport)
|
||||
<div class="social-description">
|
||||
<h2>{!! $user->home_airport->icao !!}</h2>
|
||||
<p>Home Airport</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if($user->current_airport)
|
||||
<div class="social-description">
|
||||
<h2>{!! $user->current_airport->icao !!}</h2>
|
||||
<p>Current Airport</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if(Auth::check() && $user->id === Auth::user()->id)
|
||||
<div class="clearfix" style="height: 50px;"></div>
|
||||
<div class="row">
|
||||
<div class="col-md-1"></div>
|
||||
<div class="col-sm-10">
|
||||
<a href="{!! route('frontend.profile.edit', ['id'=>$user->id]) !!}" class="pull-right btn btn-primary">edit</a>
|
||||
<h3 class="description">your profile</h3>
|
||||
<table class="table table-full-width">
|
||||
<tr>
|
||||
<td>Email</td>
|
||||
<td>{!! $user->email !!}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>API Key<p class="description">don't share this!</p></td>
|
||||
<td>{!! $user->api_key !!}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Timezone</td>
|
||||
<td>{!! $user->timezone !!}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
{{--<div class="container profile-page">
|
||||
<div class="page-header page-header-small text-color-dark-beige">
|
||||
<div class="container text-color-dark-beige">
|
||||
<div class="content-center" style="color: #9b9992;">
|
||||
<div class="photo-container">
|
||||
<img src="{!! public_asset('/assets/frontend/img/logo.svg') !!}" alt="">
|
||||
</div>
|
||||
<h3 class="title">{!! $user->name !!}</h3>
|
||||
<h6>{!! $user->rank->name !!}</h6>
|
||||
<p class="description" style="color: #9A9A9A;">
|
||||
{!! $user->airline->name !!}
|
||||
</p>
|
||||
<br /><br />
|
||||
<div class="content" style="max-width: 650px;">
|
||||
|
||||
<div class="social-description">
|
||||
<h2>{!! $user->flights!!}</h2>
|
||||
<p>Flights</p>
|
||||
</div>
|
||||
|
||||
<div class="social-description">
|
||||
<h2>{!! \App\Facades\Utils::secondsToTimeString($user->flight_time, false)!!}</h2>
|
||||
<p>Flight Hours</p>
|
||||
</div>
|
||||
|
||||
@if($user->home_airport)
|
||||
<div class="social-description">
|
||||
<h2>{!! $user->home_airport->icao !!}</h2>
|
||||
<p>Home Airport</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if($user->current_airport)
|
||||
<div class="social-description">
|
||||
<h2>{!! $user->current_airport->icao !!}</h2>
|
||||
<p>Current Airport</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>--}}
|
||||
|
||||
@endsection
|
||||
|
Loading…
Reference in New Issue
Block a user