Prechádzať zdrojové kódy

flusso conferma cambio pwd

FabioFratini 7 mesiacov pred
rodič
commit
50dee7cca7

+ 41 - 2
app/Http/Controllers/PasswordResetController.php

@@ -88,27 +88,34 @@ class PasswordResetController extends Controller
         ]);
 
         try {
+            // Verify reset token
             $resetRecord = $this->verifyResetToken($request->email, $request->token);
 
             if (!$resetRecord) {
                 return back()->with('error', 'Token non valido o scaduto.');
             }
 
+            // Get user from master database
             $user = $this->findUserInMasterDatabase($request->email);
 
             if (!$user) {
                 return back()->with('error', 'Utente non trovato.');
             }
 
+            // Update password in both databases
             $this->updatePasswordInBothDatabases($request->email, $request->password, $user);
 
+            // Delete reset token
             $this->deleteResetToken($request->email);
 
-            Log::info('Password reset completed', [
+            // Send password change notification
+            $this->sendPasswordChangeNotification($request->email, $user->name);
+
+            Log::info('Password reset completed with notification', [
                 'email' => $request->email
             ]);
 
-            return redirect('/')->with('success', 'Password aggiornata con successo. Puoi ora effettuare il login.');
+            return redirect('/')->with('success', 'Password aggiornata con successo. Ti abbiamo inviato una email di conferma.');
         } catch (\Exception $e) {
             Log::error('Password reset failed', [
                 'email' => $request->email,
@@ -360,6 +367,38 @@ class PasswordResetController extends Controller
         }
     }
 
+    private function sendPasswordChangeNotification($email, $name)
+    {
+        try {
+            $emailData = [
+                'name' => $name,
+                'email' => $email,
+                'change_time' => now()->format('d/m/Y H:i'),
+                'ip_address' => request()->ip()
+            ];
+
+            Mail::send('emails.password-changed', $emailData, function ($message) use ($email, $name) {
+                $message->to($email, $name)
+                    ->subject('La tua password è stata modificata')
+                    ->from(config('mail.from.address'), config('mail.from.name'));
+            });
+
+            Log::info('Password change notification sent', [
+                'email' => $email,
+                'name' => $name
+            ]);
+
+            return true;
+        } catch (\Exception $e) {
+            Log::error('Failed to send password change notification', [
+                'email' => $email,
+                'error' => $e->getMessage()
+            ]);
+            return false;
+        }
+    }
+
+
     /**
      * Send password reset email
      */

+ 52 - 11
app/Http/Livewire/Profile.php

@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
 use Livewire\Component;
 use App\Http\Middleware\TenantMiddleware;
+use Illuminate\Support\Facades\Mail;
 
 class Profile extends Component
 {
@@ -53,12 +54,13 @@ class Profile extends Component
         $currentUser = Auth::user();
 
         try {
-            DB::beginTransaction();
-
+            // Update user in tenant database
             $user = \App\Models\User::findOrFail($currentUser->id);
             $oldEmail = $user->email;
+            $oldName = $user->name;
             $passwordChanged = !empty($this->password);
             $emailChanged = $oldEmail !== $this->email;
+            $nameChanged = $oldName !== $this->name;
 
             $user->name = $this->name;
             $user->cognome = $this->cognome;
@@ -76,22 +78,32 @@ class Profile extends Component
                 'user_id' => $user->id,
                 'tenant_database' => DB::connection()->getDatabaseName(),
                 'email_changed' => $emailChanged,
+                'name_changed' => $nameChanged,
                 'password_changed' => $passwordChanged
             ]);
 
-            if ($emailChanged || $passwordChanged || $currentUser->name !== $this->name) {
-                $this->updateMasterDatabase($currentUser, $oldEmail, $passwordChanged);
+            // Update master database if needed
+            if ($emailChanged || $passwordChanged || $nameChanged) {
+                $masterUpdated = $this->updateMasterDatabase($currentUser, $oldEmail, $passwordChanged);
             }
 
-            DB::commit();
+            // Send password change notification if password was changed
+            if ($passwordChanged) {
+                $notificationSent = $this->sendPasswordChangeNotification($this->email, $this->name);
+
+                if ($notificationSent) {
+                    session()->flash('message', 'Profilo aggiornato con successo! Ti abbiamo inviato una email di conferma per la modifica della password.');
+                } else {
+                    session()->flash('message', 'Profilo aggiornato con successo! (Errore nell\'invio dell\'email di notifica)');
+                }
+            } else {
+                session()->flash('message', 'Profilo aggiornato con successo!');
+            }
 
-            session()->flash('message', 'Profilo aggiornato con successo!');
             $this->editMode = false;
-            $this->password = '';
+            $this->password = ''; // Clear password field
 
         } catch (\Exception $e) {
-            DB::rollBack();
-
             Log::error('Profile update failed', [
                 'user_id' => $currentUser->id,
                 'error' => $e->getMessage(),
@@ -101,7 +113,6 @@ class Profile extends Component
             session()->flash('error', 'Errore durante l\'aggiornamento: ' . $e->getMessage());
         }
     }
-
     /**
      * Update user information in master database
      */
@@ -164,7 +175,6 @@ class Profile extends Component
 
             config(['database.default' => $currentConnection]);
             DB::purge('master_temp');
-
         } catch (\Exception $e) {
             Log::error('Failed to update master database', [
                 'error' => $e->getMessage(),
@@ -197,4 +207,35 @@ class Profile extends Component
     {
         return view('livewire.profile');
     }
+
+    private function sendPasswordChangeNotification($email, $name)
+    {
+        try {
+            $emailData = [
+                'name' => $name,
+                'email' => $email,
+                'change_time' => now()->format('d/m/Y H:i'),
+                'ip_address' => request()->ip()
+            ];
+
+            Mail::send('emails.password-changed', $emailData, function ($message) use ($email, $name) {
+                $message->to($email, $name)
+                    ->subject('La tua password è stata modificata')
+                    ->from(config('mail.from.address'), config('mail.from.name'));
+            });
+
+            Log::info('Password change notification sent from profile', [
+                'email' => $email,
+                'name' => $name
+            ]);
+
+            return true;
+        } catch (\Exception $e) {
+            Log::error('Failed to send password change notification from profile', [
+                'email' => $email,
+                'error' => $e->getMessage()
+            ]);
+            return false;
+        }
+    }
 }

+ 2 - 1
resources/views/auth/password-reset-form.blade.php

@@ -1,3 +1,4 @@
+<!-- resources/views/auth/password-reset-form.blade.php -->
 <!DOCTYPE html>
 <html lang="it">
 <head>
@@ -11,7 +12,7 @@
 <body>
     <div class="login--box d-flex flex-column min-vh-100 justify-content-center align-items-center">
         <img src="{{ env('LOGO', '') }}" alt="" class="img-fluid" id="login--logo" style="max-width:400px">
-        <div class="card--ui mt-5">
+        <div class="card--ui mt-5" style="width: 400px; height: 350px;">
             <p class="form--title text-center mb-4">Imposta Nuova Password</p>
 
             @if(session('success'))

+ 1 - 1
resources/views/auth/password-reset-request.blade.php

@@ -12,7 +12,7 @@
 <body>
     <div class="login--box d-flex flex-column min-vh-100 justify-content-center align-items-center">
         <img src="{{ env('LOGO', '') }}" alt="" class="img-fluid" id="login--logo" style="max-width:400px">
-        <div class="card--ui mt-5">
+        <div class="card--ui mt-5" style="width: 400px; height: 350px;">
             <p class="form--title text-center mb-4">Reset Password</p>
             <p class="text-center mb-4">Inserisci la tua email per ricevere le istruzioni di reset</p>
 

+ 80 - 0
resources/views/emails/password-changed.blade.php

@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html lang="it">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Password Modificata</title>
+    <style>
+        body {
+            font-family: Arial, sans-serif;
+            line-height: 1.6;
+            color: #333;
+            max-width: 600px;
+            margin: 0 auto;
+            padding: 20px;
+        }
+        .header {
+            background-color: #28a745;
+            color: white;
+            padding: 20px;
+            text-align: center;
+            border-radius: 8px 8px 0 0;
+        }
+        .content {
+            background-color: #f8f9fa;
+            padding: 30px;
+            border-radius: 0 0 8px 8px;
+        }
+        .warning {
+            background-color: #fff3cd;
+            border: 1px solid #ffeaa7;
+            color: #856404;
+            padding: 15px;
+            border-radius: 5px;
+            margin: 20px 0;
+        }
+        .footer {
+            margin-top: 30px;
+            padding-top: 20px;
+            border-top: 1px solid #dee2e6;
+            font-size: 14px;
+            color: #6c757d;
+        }
+        .brand {
+            color: #0C6197;
+            font-weight: bold;
+        }
+    </style>
+</head>
+<body>
+    <div class="header">
+        <h1>🔒 Password Modificata</h1>
+    </div>
+
+    <div class="content">
+        <h2>Ciao {{ $name }},</h2>
+
+        <p>ti confermiamo che la tua password su <span class="brand">Leezard.cloud</span> è stata modificata con successo.</p>
+
+        <div class="warning">
+            <strong>⚠️ Importante:</strong> Se non sei stato tu a effettuare questa operazione, ti invitiamo a contattarci immediatamente.
+        </div>
+
+        <p>Se hai modificato la password tu stesso, puoi ignorare questa email.</p>
+
+        <p>Per maggiore sicurezza, assicurati sempre di:</p>
+        <ul>
+            <li>Utilizzare password uniche e complesse</li>
+            <li>Non condividere le tue credenziali con nessuno</li>
+            <li>Effettuare il logout dai dispositivi condivisi</li>
+        </ul>
+
+        <div class="footer">
+            <p>Grazie,<br>
+            Il team di <span class="brand">Leezard.cloud</span></p>
+            <p>Data modifica: {{ date('d/m/Y H:i') }}</p>
+            <p>Questa email è stata generata automaticamente. Per favore, non rispondere a questo indirizzo.</p>
+        </div>
+    </div>
+</body>
+</html>

+ 2 - 2
resources/views/login.blade.php

@@ -15,9 +15,9 @@
 
     <div class="login--box d-flex flex-column min-vh-100 justify-content-center align-items-center">
         <img src="{{env('LOGO', '')}}" alt="" class="img-fluid" id="login--logo"  style="max-width:400px">
-        <div class="card--ui mt-5">
+        <div class="card--ui mt-5" style="width: 400px; height: 300px;">
 
-            <p class="form--title text-center mb-4">Fai Login per accedere a tutte le funzioni</p>
+            <p class="form--title text-center mb-4">Effetua la Login per accedere a tutte le funzioni</p>
             <form action="/login" method="POST">
                 <input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">