Fix System registration form presentation and validation processing
This commit is contained in:
parent
1a5c1eff7b
commit
6e376100a5
@ -793,7 +793,7 @@ class SystemController extends Controller
|
||||
if ($request->old)
|
||||
session()->flashInput($request->old);
|
||||
|
||||
return view('system.widget.form-system')
|
||||
return view('system.widget.system')
|
||||
->with('action',$request->action)
|
||||
->with('o',$o)
|
||||
->with('errors',new ViewErrorBag);
|
||||
|
@ -53,39 +53,32 @@ class SystemRegister extends FormRequest
|
||||
*/
|
||||
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 [];
|
||||
|
||||
$so = $this->route('o');
|
||||
if ((! $so) && ($request->action === 'register'))
|
||||
return [];
|
||||
|
||||
if (((! $so) || (! $so->exists)) && ($request->action === 'create'))
|
||||
return [
|
||||
'name' => 'required|min:3',
|
||||
];
|
||||
|
||||
return array_filter(array_merge(
|
||||
[
|
||||
'name' => 'required|min:3',
|
||||
],
|
||||
($so->exists || ($request->action !== 'create')) ? [
|
||||
'location' => 'required|min:3',
|
||||
'sysop' => 'required|min:3',
|
||||
'phone' => 'nullable|regex:/^([0-9-]+)$/',
|
||||
'address' => 'nullable|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i',
|
||||
'port' => 'nullable|digits_between:2,5',
|
||||
'method' => 'nullable|numeric',
|
||||
'mailer_details.*' => 'nullable|array',
|
||||
'mailer_details.*.port' => 'nullable|digits_between:2,5',
|
||||
'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',
|
||||
] : [],
|
||||
));
|
||||
return array_filter(array_merge([
|
||||
'name' => 'required|min:3',
|
||||
'location' => 'required|min:3',
|
||||
'sysop' => 'required|min:3',
|
||||
'phone' => 'nullable|regex:/^([0-9-]+)$/',
|
||||
'address' => 'nullable|regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i',
|
||||
'port' => 'nullable|digits_between:2,5',
|
||||
'method' => 'nullable|numeric',
|
||||
'mailer_details.*' => 'nullable|array',
|
||||
'mailer_details.*.port' => 'nullable|digits_between:2,5',
|
||||
'zt_id' => 'nullable|size:10|regex:/^([A-Fa-f0-9]){10}$/|unique:systems,zt_id,'.($so ? $so->id : 0),
|
||||
'pkt_type' => ['required',Rule::in(array_keys(Packet::PACKET_TYPES))],
|
||||
],($so && $so->exists) ? [
|
||||
'users' => 'nullable|array|min:1|max:2',
|
||||
'active' => 'required|boolean',
|
||||
'hold' => 'required|boolean',
|
||||
'pollmode' => 'required|integer|min:0|max:2',
|
||||
'heartbeat' => 'nullable|integer|min:0|max:48',
|
||||
] : []));
|
||||
}
|
||||
}
|
@ -1,33 +1,35 @@
|
||||
<!-- $o = System::class -->
|
||||
<div class="row">
|
||||
<div class="col-xl-9 col-12">
|
||||
<div class="row pt-0">
|
||||
<div class="col-12">
|
||||
<h4 class="mb-0 pb-2">System Users</h4>
|
||||
@can('admin',$o)
|
||||
<div class="row pt-0">
|
||||
<div class="col-12">
|
||||
<h4 class="mb-0 pb-2">System Users</h4>
|
||||
|
||||
<div class="row pt-0">
|
||||
<!-- Users -->
|
||||
<div class="col-6">
|
||||
<label for="users" class="form-label">Owners</label>
|
||||
<div class="input-group has-validation">
|
||||
<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[]">
|
||||
<option value=""> </option>
|
||||
@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>
|
||||
@endforeach
|
||||
</select>
|
||||
<div class="row pt-0">
|
||||
<!-- Users -->
|
||||
<div class="col-6">
|
||||
<label for="users" class="form-label">Owners</label>
|
||||
<div class="input-group has-validation">
|
||||
<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[]">
|
||||
<option value=""> </option>
|
||||
@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>
|
||||
@endforeach
|
||||
</select>
|
||||
|
||||
<span class="invalid-feedback" role="alert">
|
||||
@error('users')
|
||||
{{ $message }}
|
||||
@enderror
|
||||
</span>
|
||||
<span class="invalid-feedback" role="alert">
|
||||
@error('users')
|
||||
{{ $message }}
|
||||
@enderror
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endcan
|
||||
|
||||
<div class="row pt-4">
|
||||
<div class="col-12">
|
||||
@ -53,6 +55,7 @@
|
||||
</div>
|
||||
|
||||
<!-- ZeroTier ID -->
|
||||
@can('admin',$o)
|
||||
<div class="col-5">
|
||||
<label for="zt_id" class="form-label">ZeroTier ID</label>
|
||||
<div class="input-group has-validation">
|
||||
@ -65,6 +68,7 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@endcan
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
@ -40,13 +40,11 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (old('submit') !== 'create')
|
||||
<div class="row">
|
||||
<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>
|
||||
</div>
|
||||
<div class="row">
|
||||
<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>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -77,7 +75,7 @@
|
||||
@section('page-scripts')
|
||||
@js('select2')
|
||||
|
||||
<script type="text/javascript">
|
||||
<script type='text/javascript'>
|
||||
$(document).ready(function() {
|
||||
$('#system').select2({
|
||||
placeholder: 'See if your BBS exists',
|
||||
@ -86,7 +84,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
<script type='text/javascript'>
|
||||
var system_id;
|
||||
var noauth = new bootstrap.Modal(document.getElementById('no-auth'), {});
|
||||
|
||||
@ -96,6 +94,10 @@
|
||||
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) {
|
||||
$.ajax({
|
||||
url : '{{ url('user/system/register') }}',
|
||||
|
Loading…
Reference in New Issue
Block a user