Regenerate API key
This commit is contained in:
@@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Jackiedo\Timezonelist\Facades\Timezonelist;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Facades\Utils;
|
||||
use App\Repositories\AirlineRepository;
|
||||
use App\Repositories\AirportRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
@@ -108,9 +109,24 @@ class ProfileController extends AppBaseController
|
||||
$req_data['password'] = Hash::make($req_data['password']);
|
||||
}
|
||||
|
||||
$user = $this->userRepo->update($req_data, $id);
|
||||
$this->userRepo->update($req_data, $id);
|
||||
|
||||
Flash::success('Profile updated successfully!');
|
||||
return redirect(route('frontend.profile.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate the user's API key
|
||||
*/
|
||||
public function regen_apikey(Request $request)
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
Log::info('Regenerating API key "'.$user->pilot_id.'"');
|
||||
|
||||
$user->api_key = Utils::generateApiKey();
|
||||
$user->save();
|
||||
|
||||
flash('New API key generated!')->success();
|
||||
return redirect(route('frontend.profile.index'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,21 +62,36 @@ class User extends Authenticatable
|
||||
];
|
||||
|
||||
public static $rules = [
|
||||
|
||||
'name' => 'required',
|
||||
'email' => 'required|email|unique:users,email',
|
||||
];
|
||||
|
||||
public function getPilotIdAttribute($value)
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPilotIdAttribute()
|
||||
{
|
||||
$length = setting('pilots.id_length');
|
||||
return $this->airline->icao . str_pad($this->id, $length, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function getGravatarAttribute($value)
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentAttribute()
|
||||
{
|
||||
return $this->getPilotIdAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getGravatarAttribute()
|
||||
{
|
||||
$size = 80;
|
||||
$default = 'https://en.gravatar.com/userimage/12856995/7c7c1da6387853fea65ff74983055386.png';
|
||||
return "https://www.gravatar.com/avatar/" .
|
||||
md5( strtolower( trim( $this->email) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
|
||||
return 'https://www.gravatar.com/avatar/' .
|
||||
md5(strtolower(trim($this->email))) . '?d=' . urlencode($default ) . '&s=' . $size;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,8 +27,11 @@ Route::group([
|
||||
Route::post('flights/save', 'FlightController@save')->name('flights.save');
|
||||
Route::resource('flights', 'FlightController');
|
||||
|
||||
Route::resource('profile', 'ProfileController');
|
||||
Route::resource('pireps', 'PirepController');
|
||||
|
||||
Route::get('profile/regen_apikey', 'ProfileController@regen_apikey')
|
||||
->name('profile.regen_apikey');
|
||||
Route::resource('profile', 'ProfileController');
|
||||
});
|
||||
|
||||
Auth::routes();
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
</div>
|
||||
<div class="collapse navbar-collapse justify-content-end" id="navigation">
|
||||
<ul class="navbar-nav">
|
||||
|
||||
@if(Auth::check())
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{!! url('/dashboard') !!}">
|
||||
|
||||
@@ -8,14 +8,9 @@
|
||||
@else
|
||||
<div class="alert
|
||||
alert-{{ session('flash_notification.level') }}
|
||||
{{ session()->has('flash_notification.important') ? 'alert-important' : '' }}"
|
||||
>
|
||||
{{ session()->has('flash_notification.important') ? 'alert-important' : '' }}">
|
||||
@if(session()->has('flash_notification.important'))
|
||||
<button type="button"
|
||||
class="close"
|
||||
data-dismiss="alert"
|
||||
aria-hidden="true"
|
||||
>×</button>
|
||||
<button type="button"class="close" data-dismiss="alert">×</button>
|
||||
@endif
|
||||
|
||||
{!! session('flash_notification.message') !!}
|
||||
|
||||
@@ -43,12 +43,21 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{--
|
||||
show the details/edit fields only for the currently logged in user
|
||||
--}}
|
||||
@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>
|
||||
<div class="col-sm-12">
|
||||
<div class="text-right">
|
||||
<a href="{!! route('frontend.profile.regen_apikey') !!}" class="btn btn-warning"
|
||||
onclick="return confirm('Are you sure? This will reset your API key.')">new api key</a>
|
||||
|
||||
<a href="{!! route('frontend.profile.edit', ['id' => $user->id]) !!}"
|
||||
class="btn btn-primary">edit</a>
|
||||
</div>
|
||||
|
||||
<h3 class="description">your profile</h3>
|
||||
<table class="table table-full-width">
|
||||
<tr>
|
||||
@@ -56,7 +65,7 @@
|
||||
<td>{!! $user->email !!}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>API Key<p class="description">don't share this!</p></td>
|
||||
<td>API Key <span class="description">don't share this!</span></td>
|
||||
<td>{!! $user->api_key !!}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -67,49 +76,4 @@
|
||||
</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
|
||||
|
||||
Reference in New Issue
Block a user