++ fix area profilo
This commit is contained in:
13
HANDOFF.md
13
HANDOFF.md
@@ -167,10 +167,15 @@ quale.
|
|||||||
Tre ritocchi minori ma con qualche implicazione:
|
Tre ritocchi minori ma con qualche implicazione:
|
||||||
|
|
||||||
- **Pagina profilo** (`Profile` → rotta `profilo`, nome `profile`) accessibile a
|
- **Pagina profilo** (`Profile` → rotta `profilo`, nome `profile`) accessibile a
|
||||||
ogni utente loggato (nel gruppo `auth`, nessun permesso): mostra nome, email e
|
ogni utente loggato (nel gruppo `auth`, nessun permesso): l'utente corrente può
|
||||||
qualifica del solo utente corrente (sola lettura). Nell'header il blocco utente
|
modificare il proprio nome/cognome ed email (`updateProfile`) e cambiare la
|
||||||
è ora un link a questa pagina, con nome in evidenza ed `email · qualifica`
|
password (`updatePassword`, con verifica della password attuale via regola
|
||||||
sotto. Non esiste un campo "username": l'email fa da identificativo.
|
`current_password`; il cast `hashed` cifra al salvataggio). Nell'header il
|
||||||
|
blocco utente è un link a questa pagina, con nome in evidenza ed
|
||||||
|
`email · qualifica` sotto. Non esiste un campo "username" né "cognome"
|
||||||
|
separato: `name` è il nome completo (etichettato "Nome e cognome") e l'email fa
|
||||||
|
da identificativo. La qualifica (ruolo) non è modificabile dal profilo — resta
|
||||||
|
in gestione all'admin.
|
||||||
- **Viewer PDF pubblico**: oltre a territorio/proclamatore/data mostra ora
|
- **Viewer PDF pubblico**: oltre a territorio/proclamatore/data mostra ora
|
||||||
*giorni assegnato*, *consegna prevista* e *scadenza*. Sono attributi calcolati
|
*giorni assegnato*, *consegna prevista* e *scadenza*. Sono attributi calcolati
|
||||||
su `Assegnazione` (`data_consegna_presunta`, `giorni_alla_scadenza`) basati
|
su `Assegnazione` (`data_consegna_presunta`, `giorni_alla_scadenza`) basati
|
||||||
|
|||||||
@@ -2,10 +2,61 @@
|
|||||||
|
|
||||||
namespace App\Livewire;
|
namespace App\Livewire;
|
||||||
|
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class Profile extends Component
|
class Profile extends Component
|
||||||
{
|
{
|
||||||
|
public string $name = '';
|
||||||
|
public string $email = '';
|
||||||
|
|
||||||
|
public string $current_password = '';
|
||||||
|
public string $password = '';
|
||||||
|
public string $password_confirmation = '';
|
||||||
|
|
||||||
|
public function mount(): void
|
||||||
|
{
|
||||||
|
$user = auth()->user();
|
||||||
|
$this->name = $user->name;
|
||||||
|
$this->email = $user->email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateProfile(): void
|
||||||
|
{
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
|
$validated = $this->validate([
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'email' => ['required', 'email', 'max:255', Rule::unique('users', 'email')->ignore($user->id)],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user->update([
|
||||||
|
'name' => $validated['name'],
|
||||||
|
'email' => $validated['email'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
session()->flash('profile_success', 'Profilo aggiornato con successo.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatePassword(): void
|
||||||
|
{
|
||||||
|
// `current_password` verifica che la password attuale digitata combaci
|
||||||
|
// con quella dell'utente loggato prima di consentire il cambio.
|
||||||
|
$this->validate([
|
||||||
|
'current_password' => ['required', 'current_password'],
|
||||||
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Il cast `hashed` sul modello User cifra il valore in fase di salvataggio.
|
||||||
|
auth()->user()->update([
|
||||||
|
'password' => $this->password,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->reset(['current_password', 'password', 'password_confirmation']);
|
||||||
|
|
||||||
|
session()->flash('password_success', 'Password aggiornata con successo.');
|
||||||
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.profile', [
|
return view('livewire.profile', [
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
<h1 class="text-2xl font-bold text-gray-900">Il mio profilo</h1>
|
<h1 class="text-2xl font-bold text-gray-900">Il mio profilo</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="max-w-2xl bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
|
<div class="max-w-2xl space-y-6">
|
||||||
{{-- Intestazione: avatar iniziale + nome --}}
|
{{-- Intestazione: avatar iniziale + nome --}}
|
||||||
<div class="p-6 flex items-center gap-4 border-b border-gray-100">
|
<div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6 flex items-center gap-4">
|
||||||
<div class="h-16 w-16 flex-none rounded-full flex items-center justify-center text-white text-2xl font-bold shadow-sm"
|
<div class="h-16 w-16 flex-none rounded-full flex items-center justify-center text-white text-2xl font-bold shadow-sm"
|
||||||
style="background:linear-gradient(135deg,#4f46e5,#6366f1)">
|
style="background:linear-gradient(135deg,#4f46e5,#6366f1)">
|
||||||
{{ strtoupper(mb_substr($user->name, 0, 1)) }}
|
{{ strtoupper(mb_substr($user->name, 0, 1)) }}
|
||||||
@@ -25,20 +25,70 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{-- Dettagli --}}
|
{{-- Dati profilo --}}
|
||||||
<dl class="divide-y divide-gray-100">
|
<div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
|
||||||
<div class="px-6 py-4 grid grid-cols-1 sm:grid-cols-3 gap-1 sm:gap-4">
|
<h3 class="text-lg font-semibold text-gray-900 mb-1">Dati profilo</h3>
|
||||||
<dt class="text-sm font-medium text-gray-500">Nome</dt>
|
<p class="text-sm text-gray-500 mb-4">Aggiorna nome e cognome ed email.</p>
|
||||||
<dd class="text-sm text-gray-900 sm:col-span-2">{{ $user->name }}</dd>
|
|
||||||
</div>
|
@if(session('profile_success'))
|
||||||
<div class="px-6 py-4 grid grid-cols-1 sm:grid-cols-3 gap-1 sm:gap-4">
|
<div class="mb-4 rounded-lg bg-green-50 border border-green-200 px-4 py-2.5 text-sm text-green-800">
|
||||||
<dt class="text-sm font-medium text-gray-500">Email</dt>
|
{{ session('profile_success') }}
|
||||||
<dd class="text-sm text-gray-900 sm:col-span-2 break-all">{{ $user->email }}</dd>
|
</div>
|
||||||
</div>
|
@endif
|
||||||
<div class="px-6 py-4 grid grid-cols-1 sm:grid-cols-3 gap-1 sm:gap-4">
|
|
||||||
<dt class="text-sm font-medium text-gray-500">Qualifica</dt>
|
<form wire:submit="updateProfile" class="space-y-4">
|
||||||
<dd class="text-sm text-gray-900 sm:col-span-2">{{ ucfirst($user->roles->first()?->name ?? 'utente') }}</dd>
|
<div>
|
||||||
</div>
|
<label for="name" class="block text-sm font-medium text-gray-700">Nome e cognome</label>
|
||||||
</dl>
|
<input wire:model="name" type="text" id="name" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm">
|
||||||
|
@error('name') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="email" class="block text-sm font-medium text-gray-700">Email</label>
|
||||||
|
<input wire:model="email" type="email" id="email" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm">
|
||||||
|
@error('email') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<button type="submit" class="inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-white rounded-lg transition" style="background:#4f46e5" onmouseover="this.style.background='#4338ca'" onmouseout="this.style.background='#4f46e5'">
|
||||||
|
Salva modifiche
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Cambio password --}}
|
||||||
|
<div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
|
||||||
|
<h3 class="text-lg font-semibold text-gray-900 mb-1">Cambia password</h3>
|
||||||
|
<p class="text-sm text-gray-500 mb-4">Per motivi di sicurezza conferma la password attuale.</p>
|
||||||
|
|
||||||
|
@if(session('password_success'))
|
||||||
|
<div class="mb-4 rounded-lg bg-green-50 border border-green-200 px-4 py-2.5 text-sm text-green-800">
|
||||||
|
{{ session('password_success') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<form wire:submit="updatePassword" class="space-y-4">
|
||||||
|
<div>
|
||||||
|
<label for="current_password" class="block text-sm font-medium text-gray-700">Password attuale</label>
|
||||||
|
<input wire:model="current_password" type="password" id="current_password" autocomplete="current-password" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm">
|
||||||
|
@error('current_password') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<label for="password" class="block text-sm font-medium text-gray-700">Nuova password</label>
|
||||||
|
<input wire:model="password" type="password" id="password" autocomplete="new-password" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm">
|
||||||
|
@error('password') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="password_confirmation" class="block text-sm font-medium text-gray-700">Conferma nuova password</label>
|
||||||
|
<input wire:model="password_confirmation" type="password" id="password_confirmation" autocomplete="new-password" class="mt-1 block w-full rounded-lg border-gray-300 shadow-sm focus:ring-indigo-500 focus:border-indigo-500 text-sm">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<button type="submit" class="inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-white rounded-lg transition" style="background:#4f46e5" onmouseover="this.style.background='#4338ca'" onmouseout="this.style.background='#4f46e5'">
|
||||||
|
Aggiorna password
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user