Enabled form validation

This commit is contained in:
Deon George 2023-04-12 23:18:26 +10:00
parent f01f88b3bd
commit eafae02c7b
10 changed files with 87 additions and 28 deletions

View File

@ -2,6 +2,7 @@
namespace App\Classes\LDAP\Schema; namespace App\Classes\LDAP\Schema;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@ -271,6 +272,7 @@ final class AttributeType extends Base {
case 'type': return $this->type; case 'type': return $this->type;
case 'usage': return $this->usage; case 'usage': return $this->usage;
case 'used_in_object_classes': return $this->used_in_object_classes; 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); default: return parent::__get($key);
} }

View File

@ -112,10 +112,10 @@ class HomeController extends Controller
]; ];
}); });
if (Session::has('dn')) if (old('dn'))
return view('dn') return view('dn')
->with('bases',$bases) ->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); ->with('dn',$dn);
else else
return view('home') return view('home')

View File

@ -23,9 +23,12 @@ class EntryRequest extends FormRequest
*/ */
public function rules() public function rules()
{ {
return [ return config('server')
'dn'=>'string|min:3', ->schema('attributetypes')
'objectclass'=>'array|min:1', ->intersectByKeys($this->request)
]; ->transform(function($item) { return $item->validation; })
->filter()
->flatMap(function($item) { return $item; })
->toArray();
} }
} }

View File

@ -111,4 +111,19 @@ return [
| |
*/ */
'datetime_format' => 'Y-m-d H:i:s', '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']],
],
]; ];

View File

@ -229,7 +229,11 @@ p {
} }
/** Make our placeholder text on forms lighter **/ /** Make our placeholder text on forms lighter **/
.form-control::placeholder { .form-control::placeholder {
color: #a0aec0; 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;
}

View File

@ -4,7 +4,14 @@
<div id="{{ $o->name_lc }}"> <div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value) @foreach (old($o->name_lc,$o->values) as $value)
@if ($edit && ! $o->is_rdn) @if ($edit && ! $o->is_rdn)
<input class="form-control mb-1 @if($x=($o->values->search($value) === FALSE)) border-focus @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ Arr::get($o->values,$loop->index) ?: '['.__('NEW').']' }}" readonly="true"> <div class="input-group has-validation">
<input type="text" class="form-control @if($e=$errors->get($o->name_lc.'.'.$loop->index))is-invalid @endif mb-1 @if($o->values->search($value) === FALSE) border-focus @endif" name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ ! is_null($x=Arr::get($o->values,$loop->index)) ? $x : '['.__('NEW').']' }}" readonly="true">
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
</div>
</div>
@else @else
{{ $value }}<br> {{ $value }}<br>
@endif @endif

View File

@ -1,5 +1,9 @@
<!-- $o=Binary\JpegPhoto::class --> <!-- $o=Binary\JpegPhoto::class -->
<table class="table table-borderless p-0 m-0"> @if($edit)
<div class="input-group has-validation @if($e=$errors->get($o->name_lc))is-invalid @endif">
@endif
<table class="table table-borderless p-0 m-0">
<tr> <tr>
@foreach ($o->values as $value) @foreach ($o->values as $value)
@switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE)) @switch ($x=$f->buffer($value,FILEINFO_MIME_TYPE))
@ -16,4 +20,14 @@
@endswitch @endswitch
@endforeach @endforeach
</tr> </tr>
</table> </table>
@if($edit)
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
</div>
</div>
@endif

View File

@ -4,7 +4,14 @@
<div id="{{ $o->name_lc }}"> <div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value) @foreach (old($o->name_lc,$o->values) as $value)
@if ($edit && ($value === NULL || (! $o->isStructural($value)))) @if ($edit && ($value === NULL || (! $o->isStructural($value))))
<input class="form-control mb-1 @if($o->values->search($value) === FALSE) border-focus @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ Arr::get($o->values,$loop->index) ?: '['.__('NEW').']' }}" readonly="true"> <div class="input-group has-validation">
<input type="text" class="form-control @if($e=$errors->get($o->name_lc.'.'.$loop->index))is-invalid @endif mb-1 @if($o->values->search($value) === FALSE) border-focus @endif" name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ ! is_null($x=Arr::get($o->values,$loop->index)) ? $x : '['.__('NEW').']' }}" readonly="true">
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
</div>
</div>
@else @else
{{ $value }} {{ $value }}
@if ($o->isStructural($value)) @if ($o->isStructural($value))

View File

@ -4,7 +4,14 @@
<div id="{{ $o->name_lc }}"> <div id="{{ $o->name_lc }}">
@foreach (old($o->name_lc,$o->values) as $value) @foreach (old($o->name_lc,$o->values) as $value)
@if ($edit) @if ($edit)
<input type="password" class="form-control mb-1 @if($x=($o->values->search($value) === FALSE)) border-focus @endif" type="text" name="{{ $o->name_lc }}[]" value="{{ str_repeat('*',10) }}" readonly="true"> <div class="input-group has-validation">
<input type="password" class="form-control @if($e=$errors->get($o->name_lc.'.'.$loop->index))is-invalid @endif mb-1 @if($o->values->search($value) === FALSE) border-focus @endif" name="{{ $o->name_lc }}[]" value="{{ str_repeat('*',10) }}" readonly="true">
<div class="invalid-feedback pb-2">
@if($e)
{{ join('|',$e) }}
@endif
</div>
</div>
@else @else
{{ $value }}<br> {{ $value }}<br>
@endif @endif

View File

@ -75,7 +75,7 @@
<div class="tab-content"> <div class="tab-content">
<!-- All Attributes --> <!-- All Attributes -->
<div class="tab-pane active" id="attributes" role="tabpanel"> <div class="tab-pane active" id="attributes" role="tabpanel">
<form id="form-entry" method="POST" action="{{ url('entry/update') }}"> <form id="form-entry" method="POST" class="needs-validation" action="{{ url('entry/update') }}" novalidate>
@csrf @csrf
<input type="hidden" name="dn" value="{{ $o->getDNSecure() }}"> <input type="hidden" name="dn" value="{{ $o->getDNSecure() }}">