From 6e376100a587437d503394acce5b3e0fa6ea1ead Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 26 Apr 2024 12:23:55 +1000 Subject: [PATCH] Fix System registration form presentation and validation processing --- app/Http/Controllers/SystemController.php | 2 +- app/Http/Requests/SystemRegister.php | 53 ++++++++----------- .../views/system/widget/system.blade.php | 46 ++++++++-------- .../views/user/system/register.blade.php | 18 ++++--- 4 files changed, 59 insertions(+), 60 deletions(-) diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index be10588..b459062 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -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); diff --git a/app/Http/Requests/SystemRegister.php b/app/Http/Requests/SystemRegister.php index 69a5653..ad75a16 100644 --- a/app/Http/Requests/SystemRegister.php +++ b/app/Http/Requests/SystemRegister.php @@ -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', + ] : [])); } } \ No newline at end of file diff --git a/resources/views/system/widget/system.blade.php b/resources/views/system/widget/system.blade.php index 8add8cc..467f786 100644 --- a/resources/views/system/widget/system.blade.php +++ b/resources/views/system/widget/system.blade.php @@ -1,33 +1,35 @@
-
-
-

System Users

+ @can('admin',$o) +
+
+

System Users

-
- -
- -
- - +
+ +
+ +
+ + - - @error('users') - {{ $message }} - @enderror - + + @error('users') + {{ $message }} + @enderror + +
-
+ @endcan
@@ -53,6 +55,7 @@
+ @can('admin',$o)
@@ -65,6 +68,7 @@
+ @endcan
diff --git a/resources/views/user/system/register.blade.php b/resources/views/user/system/register.blade.php index d4a70ed..53d479c 100644 --- a/resources/views/user/system/register.blade.php +++ b/resources/views/user/system/register.blade.php @@ -40,13 +40,11 @@
- @if (old('submit') !== 'create') -
-
- -
+
+
+
- @endif +
@@ -77,7 +75,7 @@ @section('page-scripts') @js('select2') - -