Fix System registration form presentation and validation processing
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 37s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m42s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s

This commit is contained in:
Deon George 2024-04-26 12:23:55 +10:00
parent 1a5c1eff7b
commit 6e376100a5
4 changed files with 59 additions and 60 deletions

View File

@ -793,7 +793,7 @@ class SystemController extends Controller
if ($request->old) if ($request->old)
session()->flashInput($request->old); session()->flashInput($request->old);
return view('system.widget.form-system') return view('system.widget.system')
->with('action',$request->action) ->with('action',$request->action)
->with('o',$o) ->with('o',$o)
->with('errors',new ViewErrorBag); ->with('errors',new ViewErrorBag);

View File

@ -53,39 +53,32 @@ class SystemRegister extends FormRequest
*/ */
public function rules(Request $request) public function rules(Request $request)
{ {
if ((! $request->isMethod('post')) || ($request->action === 'register')) // When the user first select register/link (get)
if (! $request->isMethod('post'))
return []; return [];
$so = $this->route('o'); $so = $this->route('o');
if ((! $so) && ($request->action === 'register'))
return [];
if (((! $so) || (! $so->exists)) && ($request->action === 'create')) return array_filter(array_merge([
return [ 'name' => 'required|min:3',
'name' => 'required|min:3', 'location' => 'required|min:3',
]; 'sysop' => 'required|min:3',
'phone' => 'nullable|regex:/^([0-9-]+)$/',
return array_filter(array_merge( 'address' => 'nullable|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i',
[ 'port' => 'nullable|digits_between:2,5',
'name' => 'required|min:3', 'method' => 'nullable|numeric',
], 'mailer_details.*' => 'nullable|array',
($so->exists || ($request->action !== 'create')) ? [ 'mailer_details.*.port' => 'nullable|digits_between:2,5',
'location' => 'required|min:3', 'zt_id' => 'nullable|size:10|regex:/^([A-Fa-f0-9]){10}$/|unique:systems,zt_id,'.($so ? $so->id : 0),
'sysop' => 'required|min:3', 'pkt_type' => ['required',Rule::in(array_keys(Packet::PACKET_TYPES))],
'phone' => 'nullable|regex:/^([0-9-]+)$/', ],($so && $so->exists) ? [
'address' => 'nullable|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i', 'users' => 'nullable|array|min:1|max:2',
'port' => 'nullable|digits_between:2,5', 'active' => 'required|boolean',
'method' => 'nullable|numeric', 'hold' => 'required|boolean',
'mailer_details.*' => 'nullable|array', 'pollmode' => 'required|integer|min:0|max:2',
'mailer_details.*.port' => 'nullable|digits_between:2,5', 'heartbeat' => 'nullable|integer|min:0|max:48',
'zt_id' => 'nullable|size:10|regex:/^([A-Fa-f0-9]){10}$/|unique:systems,zt_id,'.($so->exists ? $so->id : 0), ] : []));
'pkt_type' => ['required',Rule::in(array_keys(Packet::PACKET_TYPES))],
'users' => 'nullable|array|min:1|max:2',
] : [],
$so->exists ? [
'active' => 'required|boolean',
'hold' => 'required|boolean',
'pollmode' => 'required|integer|min:0|max:2',
'heartbeat' => 'nullable|integer|min:0|max:48',
] : [],
));
} }
} }

View File

@ -1,33 +1,35 @@
<!-- $o = System::class --> <!-- $o = System::class -->
<div class="row"> <div class="row">
<div class="col-xl-9 col-12"> <div class="col-xl-9 col-12">
<div class="row pt-0"> @can('admin',$o)
<div class="col-12"> <div class="row pt-0">
<h4 class="mb-0 pb-2">System Users</h4> <div class="col-12">
<h4 class="mb-0 pb-2">System Users</h4>
<div class="row pt-0"> <div class="row pt-0">
<!-- Users --> <!-- Users -->
<div class="col-6"> <div class="col-6">
<label for="users" class="form-label">Owners</label> <label for="users" class="form-label">Owners</label>
<div class="input-group has-validation"> <div class="input-group has-validation">
<span class="input-group-text"><i class="bi bi-people-fill"></i></span> <span class="input-group-text"><i class="bi bi-people-fill"></i></span>
<select style="width: 80%;" class="form-select @error('users') is-invalid @enderror" id="users" name="users[]"> <select style="width: 80%;" class="form-select @error('users') is-invalid @enderror" id="users" name="users[]">
<option value="">&nbsp;</option> <option value="">&nbsp;</option>
@foreach (\App\Models\User::orderBy('name')->active()->get() as $uo) @foreach (\App\Models\User::orderBy('name')->active()->get() as $uo)
<option value="{{ $uo->id }}" @if(in_array($uo->id,old('users',$o->users->pluck('id')->toArray())))selected @endif>{{ $uo->name }} <small>({{ $uo->email }})</small></option> <option value="{{ $uo->id }}" @if(in_array($uo->id,old('users',$o->users->pluck('id')->toArray())))selected @endif>{{ $uo->name }} <small>({{ $uo->email }})</small></option>
@endforeach @endforeach
</select> </select>
<span class="invalid-feedback" role="alert"> <span class="invalid-feedback" role="alert">
@error('users') @error('users')
{{ $message }} {{ $message }}
@enderror @enderror
</span> </span>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> @endcan
<div class="row pt-4"> <div class="row pt-4">
<div class="col-12"> <div class="col-12">
@ -53,6 +55,7 @@
</div> </div>
<!-- ZeroTier ID --> <!-- ZeroTier ID -->
@can('admin',$o)
<div class="col-5"> <div class="col-5">
<label for="zt_id" class="form-label">ZeroTier ID</label> <label for="zt_id" class="form-label">ZeroTier ID</label>
<div class="input-group has-validation"> <div class="input-group has-validation">
@ -65,6 +68,7 @@
</span> </span>
</div> </div>
</div> </div>
@endcan
</div> </div>
<div class="row"> <div class="row">

View File

@ -40,13 +40,11 @@
</div> </div>
</div> </div>
@if (old('submit') !== 'create') <div class="row">
<div class="row"> <div class="col-12 pb-2">
<div class="col-12 pb-2"> <button type="button" name="submit" class="btn btn-success">Next</button><span id="next" class="m-2"><i class="spinner-border spinner-border-sm text-light d-none"></i></span>
<button type="button" name="submit" class="btn btn-success">Next</button><span id="next" class="m-2"><i class="spinner-border spinner-border-sm text-light d-none"></i></span>
</div>
</div> </div>
@endif </div>
</div> </div>
</div> </div>
</div> </div>
@ -77,7 +75,7 @@
@section('page-scripts') @section('page-scripts')
@js('select2') @js('select2')
<script type="text/javascript"> <script type='text/javascript'>
$(document).ready(function() { $(document).ready(function() {
$('#system').select2({ $('#system').select2({
placeholder: 'See if your BBS exists', placeholder: 'See if your BBS exists',
@ -86,7 +84,7 @@
}); });
</script> </script>
<script> <script type='text/javascript'>
var system_id; var system_id;
var noauth = new bootstrap.Modal(document.getElementById('no-auth'), {}); var noauth = new bootstrap.Modal(document.getElementById('no-auth'), {});
@ -96,6 +94,10 @@
attr.parent().find('.invalid-feedback').empty().append(message); attr.parent().find('.invalid-feedback').empty().append(message);
} }
/**
* We have selected a BBS from the link/register form, and it's either a new entry or an existing one
* @param icon
*/
function getform(icon) { function getform(icon) {
$.ajax({ $.ajax({
url : '{{ url('user/system/register') }}', url : '{{ url('user/system/register') }}',