Add pilot ID change fields to the admin screen
This commit is contained in:
parent
337fe5cfaa
commit
567ff91de0
@ -15,6 +15,7 @@ roles:
|
||||
|
||||
users:
|
||||
- id: 1
|
||||
pilot_id: 1
|
||||
name: Admin User
|
||||
email: admin@phpvms.net
|
||||
password: admin
|
||||
@ -34,6 +35,7 @@ users:
|
||||
created_at: now
|
||||
updated_at: now
|
||||
- id: 2
|
||||
pilot_id: 2
|
||||
name: Carla Walters
|
||||
email: carla.walters68@example.com
|
||||
password: admin
|
||||
@ -50,6 +52,7 @@ users:
|
||||
opt_in: 1
|
||||
toc_accepted: 1
|
||||
- id: 3
|
||||
pilot_id: 3
|
||||
name: Raymond Pearson
|
||||
email: raymond.pearson56@example.com
|
||||
password: admin
|
||||
|
@ -5,7 +5,7 @@ namespace App\Http\Requests;
|
||||
use App\Models\Pirep;
|
||||
use App\Repositories\PirepFieldRepository;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Log;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreatePirepRequest extends FormRequest
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ namespace App\Http\Requests;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use function request;
|
||||
|
||||
class UpdateUserRequest extends FormRequest
|
||||
{
|
||||
@ -24,6 +25,13 @@ class UpdateUserRequest extends FormRequest
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return User::$rules;
|
||||
$rules = User::$rules;
|
||||
|
||||
$user_id = request('id', null);
|
||||
|
||||
// Validate if the pilot ID is already being used or not
|
||||
$rules['pilot_id'] = 'required|integer|unique:users,pilot_id,'.$user_id.',id';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
@ -96,8 +96,9 @@ class User extends Authenticatable
|
||||
];
|
||||
|
||||
public static $rules = [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email',
|
||||
'pilot_id' => 'required|integer|unique:users,pilot_id',
|
||||
'name' => 'required',
|
||||
'email' => 'required|email',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -108,6 +108,11 @@ class UserService extends Service
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function isPilotIdAlreadyUsed(int $pilot_id): bool
|
||||
{
|
||||
return User::where('pilot_id', '=', $pilot_id)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change a user's pilot ID
|
||||
*
|
||||
@ -120,7 +125,11 @@ class UserService extends Service
|
||||
*/
|
||||
public function changePilotId(User $user, int $pilot_id): User
|
||||
{
|
||||
if (User::where('pilot_id', '=', $pilot_id)->exists()) {
|
||||
if ($user->pilot_id === $pilot_id) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
if ($this->isPilotIdAlreadyUsed($pilot_id)) {
|
||||
Log::error('User with id '.$pilot_id.' already exists');
|
||||
|
||||
throw new UserPilotIdExists();
|
||||
|
@ -1,17 +1,24 @@
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-4">
|
||||
{{ Form::hidden('id') }}
|
||||
<div class="form-group col-sm-3">
|
||||
{{ Form::label('pilot_id', 'Pilot ID:') }}
|
||||
{{ Form::number('pilot_id', null, ['class' => 'form-control']) }}
|
||||
<p class="text-danger">{{ $errors->first('pilot_id') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-3">
|
||||
{{ Form::label('name', 'Name:') }}
|
||||
{{ Form::text('name', null, ['class' => 'form-control']) }}
|
||||
<p class="text-danger">{{ $errors->first('name') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-4">
|
||||
<div class="form-group col-sm-3">
|
||||
{{ Form::label('email', 'Email:') }}
|
||||
{{ Form::text('email', null, ['class' => 'form-control']) }}
|
||||
<p class="text-danger">{{ $errors->first('email') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-4">
|
||||
<div class="form-group col-sm-3">
|
||||
{{ Form::label('password', 'Password:') }}
|
||||
{{ Form::password('password', ['class' => 'form-control']) }}
|
||||
<p class="text-danger">{{ $errors->first('password') }}</p>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<table class="table table-hover table-responsive" id="users-table">
|
||||
<thead>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>Registered</th>
|
||||
@ -9,6 +10,7 @@
|
||||
<tbody>
|
||||
@foreach($users as $user)
|
||||
<tr>
|
||||
<td>{{ $user->ident }}</td>
|
||||
<td>
|
||||
@if(filled($user->country))
|
||||
<span class="flag-icon flag-icon-{{ $user->country }}"
|
||||
|
Loading…
Reference in New Issue
Block a user