From eafae02c7b44204846a309d1338c21d0a551be0b Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 12 Apr 2023 23:18:26 +1000 Subject: [PATCH] Enabled form validation --- app/Classes/LDAP/Schema/AttributeType.php | 2 + app/Http/Controllers/HomeController.php | 4 +- app/Http/Requests/EntryRequest.php | 11 +++-- config/ldap.php | 15 ++++++ public/css/fixes.css | 6 ++- .../views/components/attribute.blade.php | 9 +++- .../attribute/binary/jpegphoto.blade.php | 48 ++++++++++++------- .../attribute/objectclass.blade.php | 9 +++- .../components/attribute/password.blade.php | 9 +++- resources/views/frames/dn.blade.php | 2 +- 10 files changed, 87 insertions(+), 28 deletions(-) diff --git a/app/Classes/LDAP/Schema/AttributeType.php b/app/Classes/LDAP/Schema/AttributeType.php index acaa319..28c79ed 100644 --- a/app/Classes/LDAP/Schema/AttributeType.php +++ b/app/Classes/LDAP/Schema/AttributeType.php @@ -2,6 +2,7 @@ namespace App\Classes\LDAP\Schema; +use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; @@ -271,6 +272,7 @@ final class AttributeType extends Base { case 'type': return $this->type; case 'usage': return $this->usage; case 'used_in_object_classes': return $this->used_in_object_classes; + case 'validation': return Arr::get(config('ldap.validation'),$this->name_lc); default: return parent::__get($key); } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 9ec4bee..e24d431 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -112,10 +112,10 @@ class HomeController extends Controller ]; }); - if (Session::has('dn')) + if (old('dn')) return view('dn') ->with('bases',$bases) - ->with('o',config('server')->fetch($dn=Crypt::decryptString(Session::pull('dn')))) + ->with('o',config('server')->fetch($dn=Crypt::decryptString(old('dn')))) ->with('dn',$dn); else return view('home') diff --git a/app/Http/Requests/EntryRequest.php b/app/Http/Requests/EntryRequest.php index a57b07e..5aba0c7 100644 --- a/app/Http/Requests/EntryRequest.php +++ b/app/Http/Requests/EntryRequest.php @@ -23,9 +23,12 @@ class EntryRequest extends FormRequest */ public function rules() { - return [ - 'dn'=>'string|min:3', - 'objectclass'=>'array|min:1', - ]; + return config('server') + ->schema('attributetypes') + ->intersectByKeys($this->request) + ->transform(function($item) { return $item->validation; }) + ->filter() + ->flatMap(function($item) { return $item; }) + ->toArray(); } } \ No newline at end of file diff --git a/config/ldap.php b/config/ldap.php index d4b141f..4596e61 100644 --- a/config/ldap.php +++ b/config/ldap.php @@ -111,4 +111,19 @@ return [ | */ 'datetime_format' => 'Y-m-d H:i:s', + + /* + |-------------------------------------------------------------------------- + | Validation + |-------------------------------------------------------------------------- + | + | Default validation used for data input. + | + */ + 'validation' => [ + 'objectclass' => ['objectclass'=>['array','min:1']], + 'gidnumber' => ['gidnumber'=>['sometimes','array','max:1'],'gidnumber.*'=>['integer','max:65535']], + 'mail' => ['mail'=>['sometimes','array','min:1'],'mail.*'=>['email']], + 'uidnumber' => ['uidnumber'=>['sometimes','array','max:1'],'uidnumber.*'=>['integer','max:65535']], + ], ]; diff --git a/public/css/fixes.css b/public/css/fixes.css index 8430e33..2918683 100644 --- a/public/css/fixes.css +++ b/public/css/fixes.css @@ -229,7 +229,11 @@ p { } /** Make our placeholder text on forms lighter **/ - .form-control::placeholder { color: #a0aec0; +} + +/** Force our validation color to have a higher priority than any specified border **/ +.was-validated .form-control:invalid, .form-control.is-invalid { + border-color: #d92550 !important; } \ No newline at end of file diff --git a/resources/views/components/attribute.blade.php b/resources/views/components/attribute.blade.php index d1b3043..65f4163 100644 --- a/resources/views/components/attribute.blade.php +++ b/resources/views/components/attribute.blade.php @@ -4,7 +4,14 @@
@foreach (old($o->name_lc,$o->values) as $value) @if ($edit && ! $o->is_rdn) - +
+ +
+ @if($e) + {{ join('|',$e) }} + @endif +
+
@else {{ $value }}
@endif diff --git a/resources/views/components/attribute/binary/jpegphoto.blade.php b/resources/views/components/attribute/binary/jpegphoto.blade.php index c62128c..06d35e8 100644 --- a/resources/views/components/attribute/binary/jpegphoto.blade.php +++ b/resources/views/components/attribute/binary/jpegphoto.blade.php @@ -1,19 +1,33 @@ - - - @foreach ($o->values as $value) - @switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE)) - @case('image/jpeg') - @default - - @endswitch - @endforeach - -
- - +@if($edit) +
+@endif - @if($edit) -
@lang('Delete') - @endif -
\ No newline at end of file + + + @foreach ($o->values as $value) + @switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE)) + @case('image/jpeg') + @default + + @endswitch + @endforeach + +
+ + + + @if($edit) +
@lang('Delete') + @endif +
+ + @if($edit) +
+ @if($e) + {{ join('|',$e) }} + @endif +
+ +
+ @endif \ No newline at end of file diff --git a/resources/views/components/attribute/objectclass.blade.php b/resources/views/components/attribute/objectclass.blade.php index 0164deb..c831b6c 100644 --- a/resources/views/components/attribute/objectclass.blade.php +++ b/resources/views/components/attribute/objectclass.blade.php @@ -4,7 +4,14 @@
@foreach (old($o->name_lc,$o->values) as $value) @if ($edit && ($value === NULL || (! $o->isStructural($value)))) - +
+ +
+ @if($e) + {{ join('|',$e) }} + @endif +
+
@else {{ $value }} @if ($o->isStructural($value)) diff --git a/resources/views/components/attribute/password.blade.php b/resources/views/components/attribute/password.blade.php index 827bb68..0c2c38c 100644 --- a/resources/views/components/attribute/password.blade.php +++ b/resources/views/components/attribute/password.blade.php @@ -4,7 +4,14 @@
@foreach (old($o->name_lc,$o->values) as $value) @if ($edit) - +
+ +
+ @if($e) + {{ join('|',$e) }} + @endif +
+
@else {{ $value }}
@endif diff --git a/resources/views/frames/dn.blade.php b/resources/views/frames/dn.blade.php index 7d5e0d6..b17184b 100644 --- a/resources/views/frames/dn.blade.php +++ b/resources/views/frames/dn.blade.php @@ -75,7 +75,7 @@
-
+ @csrf