Browse Source

annulla e password min length

FabioFratini 11 tháng trước cách đây
mục cha
commit
99f0288a18

+ 23 - 0
app/Http/Livewire/User.php

@@ -34,6 +34,7 @@ class User extends Component
         'lastname.required' => 'Il cognome è obbligatorio',
         'username.required' => 'Lo username è obbligatorio',
         'email.required' => 'Il nome è obbligatorio',
+        'password.min' => 'La password deve essere di almeno 6 caratteri',
     ];
 
     public function resetFields(){
@@ -68,6 +69,9 @@ class User extends Component
     public function store()
     {
         $this->validate();
+        if (!$this->validatePassword()) {
+            return;
+        }
         try {
             $u = \App\Models\User::create([
                 'firstname' => $this->firstname,
@@ -88,6 +92,22 @@ class User extends Component
         }
     }
 
+    public function validatePassword()
+    {
+        if ($this->add && empty($this->password)) {
+            $this->addError('password', 'La password è obbligatoria');
+            return false;
+        }
+
+        if (!empty($this->password) && strlen($this->password) < 6) {
+            $this->addError('password', 'La password deve essere di almeno 6 caratteri');
+            return false;
+        }
+
+        return true;
+    }
+
+
     public function edit($id){
         try {
             $record = \App\Models\User::findOrFail($id);
@@ -112,6 +132,9 @@ class User extends Component
     public function update()
     {
         $this->validate();
+        if (!$this->validatePassword()) {
+            return;
+        }
         try {
             $updateData = [
                 'firstname' => $this->firstname,

+ 11 - 7
resources/views/components/report/modifica/footer.blade.php

@@ -1,9 +1,13 @@
+@if (!$this->validated)
     <button type="submit" class="btn btn-success mr-3" wire:click.prevent="cancel()">Annulla</button>
-    @if ($add)
-        <button type="submit" class="btn btn-primary py-3" wire:click.prevent="store()">Salva</button>
-    @endif
-    @if ($update)
-        @if (!$this->validated)
-            <button type="submit" class="btn btn-primary" wire:click.prevent="update(false)">Salva</button>
-        @endif
+@else
+    <button type="submit" class="btn btn-success mr-3" wire:click.prevent="cancel()">Chiudi</button>
+@endif
+@if ($add)
+    <button type="submit" class="btn btn-primary py-3" wire:click.prevent="store()">Salva</button>
+@endif
+@if ($update)
+    @if (!$this->validated)
+        <button type="submit" class="btn btn-primary" wire:click.prevent="update(false)">Salva</button>
     @endif
+@endif

+ 1 - 18
resources/views/livewire/users.blade.php

@@ -12,24 +12,7 @@
         </div>
     </div>
 
-    @if (session()->has('success'))
-        <div class="alert alert-success" role="alert">
-            {{ session()->get('success') }}
-        </div>
-    @endif
-    @if (session()->has('error'))
-        <div class="alert alert-danger" role="alert">
-            {{ session()->get('error') }}
-        </div>
-    @endif
-
-    @if (count($errors) > 0)
-        <div class="alert alert-danger">
-            @foreach ($errors->all() as $e)
-                {{$e}}<br>
-            @endforeach
-        </div>
-    @endif
+    @include('components.report.alerting.alert')
 
     @if(!$add && !$update)