From e7336a942b3d2868230803404af1c7a225fa4a39 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 6 Dec 2024 08:33:24 +1100 Subject: [PATCH] More changes to use form.select component. Re-engineered user BBS registration --- app/Http/Controllers/SystemController.php | 45 ++-- app/Http/Requests/SystemRegisterRequest.php | 11 +- app/Models/Policies/SystemPolicy.php | 11 +- app/Providers/AppServiceProvider.php | 5 +- .../views/components/form/select.blade.php | 2 +- resources/views/setup.blade.php | 52 +---- resources/views/system/addedit.blade.php | 68 +++--- .../system/widget/form-address.blade.php | 69 ++----- .../views/system/widget/system.blade.php | 195 ++++++++---------- .../views/user/system/register.blade.php | 115 +---------- .../user/system/register_confirm.blade.php | 57 +++++ .../system/widget/register_confirm.blade.php | 41 ---- routes/web.php | 4 +- 13 files changed, 253 insertions(+), 422 deletions(-) create mode 100644 resources/views/user/system/register_confirm.blade.php delete mode 100644 resources/views/user/system/widget/register_confirm.blade.php diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 4fec065..95902d8 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -49,6 +49,9 @@ class SystemController extends Controller $o->autohold = FALSE; $o->save(); + if ($o->wasRecentlyCreated) + $o->users()->attach(Auth::id()); + $mailers = collect($request->post('mailer_details')) ->filter(function($item) { return $item['port']; }) ->transform(function($item) { $item['active'] = Arr::get($item,'active',FALSE); return $item; }); @@ -621,39 +624,19 @@ class SystemController extends Controller */ public function register(SystemRegisterRequest $request) { - if ($request->action === 'register' && $request->name && is_numeric($request->name)) - return view('user.system.widget.register_confirm') - ->with('o',System::findOrFail($request->name)); + // During the BBS linking process, if the user selected a system will link to confirm it + if ($request->action === 'register' && $request->system_id && is_numeric($request->system_id)) + return redirect() + ->to(sprintf('user/system/register_confirm/%d',$request->system_id)); - $o = System::findOrNew(is_numeric($request->system_id) ? $request->system_id : NULL); + // Re-flash our previously input data, we must be creating a new system + session()->flashInput([ + 'name'=>$request->system_id, + 'sysop'=>Auth::user()->name, + ]); - // If the system doesnt exist, we'll create it - if (! $o->exist) { - $o->sysop = Auth::user()->name; - - foreach (['name','zt_id','location','phone','method','address','port'] as $item) - if ($request->{$item}) - $o->{$item} = $request->{$item}; - - $o->active = TRUE; - } - - if ($request->post('submit')) { - Auth::user()->systems()->save($o); - - // @todo if the system already exists and part of one of our networks, we'll need to send the registration email to confirm the address. - // @todo mark the system (or addresses) as "pending" at this stage until it is confirmed - return redirect()->to(url('system/addedit',$o->id)); - } - - // Re-flash our previously input data - if ($request->old) - session()->flashInput($request->old); - - return view('system.widget.system') - ->with('action',$request->action) - ->with('o',$o) - ->with('errors',new ViewErrorBag); + return redirect() + ->to('system/addedit'); } /** diff --git a/app/Http/Requests/SystemRegisterRequest.php b/app/Http/Requests/SystemRegisterRequest.php index 0bf2b12..6547015 100644 --- a/app/Http/Requests/SystemRegisterRequest.php +++ b/app/Http/Requests/SystemRegisterRequest.php @@ -56,8 +56,11 @@ class SystemRegisterRequest extends FormRequest return []; $so = $this->route('o'); + + // When we have selected a system during the register/linking process if ((! $so) && ($request->action === 'register')) - return []; + // If system ID is not numeric, then its a new system + return is_numeric($request->system_id) ? ['system_id'=>'required|exists:systems,id'] : []; return array_filter(array_merge([ 'name' => 'required|min:3', @@ -68,14 +71,16 @@ class SystemRegisterRequest extends FormRequest 'port' => 'nullable|digits_between:2,5', 'method' => 'nullable|numeric', 'mailer_details.*' => 'nullable|array', + // @todo Port should be present if active is true 'mailer_details.*.port' => 'nullable|digits_between:2,5', + 'mailer_details.*.active' => 'sometimes|boolean', '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' => 'sometimes|boolean', 'pollmode' => 'required|integer|min:0|max:2', + ],($so && $so->exists) ? [ + 'users' => 'nullable|array|min:1|max:2', 'heartbeat' => [ 'nullable', 'integer', diff --git a/app/Models/Policies/SystemPolicy.php b/app/Models/Policies/SystemPolicy.php index d0081c2..d602686 100644 --- a/app/Models/Policies/SystemPolicy.php +++ b/app/Models/Policies/SystemPolicy.php @@ -25,6 +25,13 @@ class SystemPolicy { use HandlesAuthorization; + public function admin(User $user, System $system): bool + { + // Site Admins can always create + // If it doesnt exist, then a user can create it. + return ($user->isAdmin() || (! $system->exists)); + } + /** * Determine whether the user can create the model. * @@ -70,9 +77,9 @@ class SystemPolicy if ($user->isAdmin()) return TRUE; - // If it doesnt exist, then its a false. + // If it doesnt exist, then its a true (they are creating it). if (! $system->exists) - return FALSE; + return TRUE; // @todo Permit ZC, RC, NC, HUB user diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index d010a02..bb40cbf 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Notification; +use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use App\Events\Echomail as EchomailEvent; @@ -18,7 +19,7 @@ use App\Helpers\PageAssets; use App\Listeners\EchomailListener; use App\Listeners\Matrix\MessageListener; use App\Notifications\Channels\{EchomailChannel,MatrixChannel,NetmailChannel}; -use App\Models\{Echomail,Netmail,User}; +use App\Models\{Echomail,Netmail,System,User}; use App\Traits\Single; class AppServiceProvider extends ServiceProvider @@ -85,5 +86,7 @@ class AppServiceProvider extends ServiceProvider // Custom Aliases $loader = AliasLoader::getInstance(); $loader->alias('PageAssets',PageAssets::class); + + Route::model('so',System::class); } } diff --git a/resources/views/components/form/select.blade.php b/resources/views/components/form/select.blade.php index 8432c1e..e34561f 100644 --- a/resources/views/components/form/select.blade.php +++ b/resources/views/components/form/select.blade.php @@ -1,6 +1,6 @@ - @if(empty($value) || isset($addnew) || isset($choose)) @isset($addnew) diff --git a/resources/views/setup.blade.php b/resources/views/setup.blade.php index c5468f1..6093bef 100644 --- a/resources/views/setup.blade.php +++ b/resources/views/setup.blade.php @@ -1,8 +1,8 @@ -@php -use App\Models\Setup; -use App\Classes\Protocol\{Binkp,EMSI,DNS}; -@endphp +@use(App\Classes\Protocol\Binkp) +@use(App\Classes\Protocol\EMSI) +@use(App\Models\Setup) +@use(App\Models\System) @extends('layouts.app') @section('htmlheader_title') @@ -23,30 +23,12 @@ use App\Classes\Protocol\{Binkp,EMSI,DNS};
- -
- - - - @error('system_id') - {{ $message }} - @else - A system is required. - @enderror - - - @if(! $o->system_id) - Add a NEW System - @else - Edit System - @endif - -
+ @php + $helper = (! $o->system_id) + ? sprintf('Add a NEW System"',url('system/addedit')) + : sprintf('Edit System',url('system/addedit',[$o->system_id])); + @endphp +
@@ -301,23 +283,9 @@ use App\Classes\Protocol\{Binkp,EMSI,DNS}; @endsection @section('page-css') - @css('select2') - -@append -@section('page-scripts') - @js('select2') - - @append \ No newline at end of file diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index 397f54e..b241555 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -617,39 +617,47 @@ @section('page-scripts') @append \ No newline at end of file diff --git a/resources/views/user/system/register.blade.php b/resources/views/user/system/register.blade.php index 537150d..c986578 100644 --- a/resources/views/user/system/register.blade.php +++ b/resources/views/user/system/register.blade.php @@ -1,16 +1,15 @@ +@use(App\Models\System) + @extends('layouts.app') @section('htmlheader_title') Register System @endsection -@php -use App\Models\System; -@endphp - @section('content') -
+ @csrf +
@@ -27,13 +26,13 @@ use App\Models\System; ->whereRaw('id NOT IN (SELECT system_id FROM "system_user")') ->cursor()) - +
- +
@@ -41,104 +40,4 @@ use App\Models\System; - - -@endsection - -@section('page-scripts') - -@append \ No newline at end of file +@endsection \ No newline at end of file diff --git a/resources/views/user/system/register_confirm.blade.php b/resources/views/user/system/register_confirm.blade.php new file mode 100644 index 0000000..585df3a --- /dev/null +++ b/resources/views/user/system/register_confirm.blade.php @@ -0,0 +1,57 @@ + +@use(App\Models\System) + +@extends('layouts.app') + +@section('htmlheader_title') + Register System +@endsection + +@section('content') + @if(! $so->address) +

Enable to complete registration

+ +

The system you selected {{ $so->name }} doesnt have mailer details, please contact that system administration to update those details first

+ @else +

System Details:

+ + + + + + + + + + + + + + + + + + + + + +
System{{ $so->name }}
Sysop{{ $so->sysop }}
Location{{ $so->location }}
Networks{{ $so->akas->pluck('ftn')->join(', ') }}
Address{{ $so->access_mailer }}
+ +

If the details are above are not correct, then please contact the (ZC) to have them corrected first.

+ +

Otherwise, if all is good, we'll send a netmail to {{ $so->sysop }} at {{ $so->access_mailer }}

with further details. + +
+ @csrf + + + + +
+
+ +
+
+
+ @endif +@endsection \ No newline at end of file diff --git a/resources/views/user/system/widget/register_confirm.blade.php b/resources/views/user/system/widget/register_confirm.blade.php deleted file mode 100644 index 956243d..0000000 --- a/resources/views/user/system/widget/register_confirm.blade.php +++ /dev/null @@ -1,41 +0,0 @@ - -

System Details:

- - - - - - - - - - - - - - - - - - - - - -
System{{ $o->name }}
Sysop{{ $o->sysop }}
Location{{ $o->location }}
Networks{{ $o->akas->pluck('ftn')->join(', ') }}
Address{{ $o->access_mailer }}
- -

If the details are above are not correct, then please contact the (ZC) to have them corrected first.

- -

Otherwise, if all is good, we'll send a netmail to {{ $o->sysop }} at {{ $o->access_mailer }}

with further details. - -
- @csrf - - - - -
-
- -
-
-
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index a4f81b1..2b15735 100644 --- a/routes/web.php +++ b/routes/web.php @@ -135,7 +135,9 @@ Route::middleware(['auth','verified','activeuser'])->group(function () { Route::view('user/system/register','user.system.register'); Route::post('user/system/register',[SystemController::class,'register']); - Route::match(['post'],'user/system/link',[SystemController::class,'system_link']); + Route::view('user/system/register_confirm/{so}','user.system.register_confirm') + ->where('so','[0-9]+'); + Route::post('user/system/link',[SystemController::class,'system_link']); /* ZONE PATHS */ Route::view('zone','zone.home');