Posta configurabile dall'app, contatti dei proclamatori, conferma email

- Server di posta in Impostazioni (password cifrata, email di prova): se
  compilato prende il posto del .env; non si esporta e l'import XML non lo
  cancella. MAIL_SCHEME=tls nel .env.example non era valido per Laravel 11.
- Proclamatori con email e telefono facoltativi, cifrati, nell'XML e
  cancellati dall'anonimizzazione; il numero apre WhatsApp.
- Dopo l'assegnazione un riquadro in evidenza con il link del PDF,
  "Invia su WhatsApp" con il messaggio pronto e la scelta "inviato /
  non ancora", che resta finché non si sceglie.
- Conferma dell'email obbligatoria per tutti gli utenti, anche esistenti:
  email in italiano, link valido senza login, nuova conferma a ogni cambio
  di indirizzo, "Reinvia conferma" in Utenti. Senza conferma restano
  raggiungibili profilo, cambio password e, per l'admin, il server di
  posta; comando utenti:conferma-email per l'emergenza.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 17:12:31 +02:00
parent e7148c7b32
commit fc8623f7db
35 changed files with 1737 additions and 14 deletions

View File

@@ -13,13 +13,16 @@ class Proclamatore extends Model
protected $table = 'proclamatori';
protected $fillable = ['nome', 'cognome', 'attivo'];
protected $fillable = ['nome', 'cognome', 'email', 'telefono', 'attivo'];
protected function casts(): array
{
return [
'nome' => 'encrypted',
'cognome' => 'encrypted',
// Facoltativi. Cifrati come nome e cognome: dati personali.
'email' => 'encrypted',
'telefono' => 'encrypted',
'attivo' => 'boolean',
];
}
@@ -27,7 +30,7 @@ class Proclamatore extends Model
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly(['attivo']) // Do NOT log nome/cognome in audit (encrypted, GDPR)
->logOnly(['attivo']) // Do NOT log nome/cognome/email/telefono in audit (encrypted, GDPR)
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
@@ -40,6 +43,46 @@ class Proclamatore extends Model
return trim($this->cognome . ' ' . $this->nome);
}
/**
* Il numero come lo vuole WhatsApp: solo cifre, con il prefisso
* internazionale. Un numero senza prefisso si considera italiano: un
* cellulare scritto "333 1234567" diventa 393331234567. Null se non c'è un
* numero utilizzabile.
*/
public function telefonoInternazionale(): ?string
{
$grezzo = trim((string) $this->telefono);
if ($grezzo === '') {
return null;
}
$cifre = preg_replace('/\D+/', '', $grezzo);
if (str_starts_with($cifre, '00') && ! str_starts_with($grezzo, '+')) {
$cifre = substr($cifre, 2);
} elseif (! str_starts_with($grezzo, '+') && (! str_starts_with($cifre, '39') || strlen($cifre) <= 10)) {
// Senza prefisso: cellulari (3…) e fissi (0…) italiani. Un
// "39…" di 11 cifre o più ha già il prefisso, scritto senza "+".
$cifre = '39' . $cifre;
}
return strlen($cifre) >= 8 && strlen($cifre) <= 15 ? $cifre : null;
}
/**
* Il link che apre una chat WhatsApp con il proclamatore, con un messaggio
* già scritto se c'è. Null se non ha un numero utilizzabile.
*/
public function whatsappUrl(?string $messaggio = null): ?string
{
$numero = $this->telefonoInternazionale();
if ($numero === null) {
return null;
}
return 'https://wa.me/' . $numero . ($messaggio !== null && $messaggio !== '' ? '?text=' . rawurlencode($messaggio) : '');
}
public function assegnazioni()
{
return $this->hasMany(Assegnazione::class, 'proclamatore_id');
@@ -63,6 +106,8 @@ class Proclamatore extends Model
{
$this->nome = 'Anonimo';
$this->cognome = 'Proclamatore #' . $this->id;
$this->email = null;
$this->telefono = null;
$this->attivo = false;
$this->save();
$this->delete(); // soft delete

View File

@@ -20,8 +20,31 @@ class Setting extends Model
'pdf_viewer_show_download',
'audit_retention_days',
'setup_completed',
'mail_host',
'mail_port',
'mail_cifratura',
'mail_username',
'mail_password',
'mail_from_address',
'mail_from_name',
];
/**
* Il server di posta: configurazione di questa installazione, non dati.
* Non si esporta e un import non la tocca (vedi XmlExchange).
*/
public const CAMPI_POSTA = [
'mail_host',
'mail_port',
'mail_cifratura',
'mail_username',
'mail_password',
'mail_from_address',
'mail_from_name',
];
protected $hidden = ['mail_password'];
protected function casts(): array
{
return [
@@ -33,6 +56,8 @@ class Setting extends Model
'home_limit_list' => 'integer',
'assignment_link_ttl_hours' => 'integer',
'audit_retention_days' => 'integer',
'mail_port' => 'integer',
'mail_password' => 'encrypted',
];
}

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@@ -9,7 +10,12 @@ use Spatie\Permission\Traits\HasRoles;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
class User extends Authenticatable
/**
* MustVerifyEmail: l'account funziona solo con l'indirizzo confermato
* (middleware `verified`, VerificaEmailController). Chi cambia email — dal
* profilo o perché la cambia l'amministratore — torna da confermare.
*/
class User extends Authenticatable implements MustVerifyEmail
{
use HasFactory, Notifiable, HasRoles, LogsActivity;
@@ -41,4 +47,32 @@ class User extends Authenticatable
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
protected static function booted(): void
{
// Un indirizzo nuovo va confermato di nuovo, chiunque lo cambi.
static::updating(function (self $utente) {
if ($utente->isDirty('email') && ! $utente->isDirty('email_verified_at')) {
$utente->email_verified_at = null;
}
});
}
/**
* Manda l'email di conferma; false se il server di posta non risponde o
* rifiuta. Chi chiama decide cosa dire: l'utente è comunque salvato, e
* l'email si può richiedere di nuovo.
*/
public function inviaConfermaEmail(): bool
{
try {
$this->sendEmailVerificationNotification();
} catch (\Throwable $e) {
report($e);
return false;
}
return true;
}
}