*/ use HasApiTokens, HasFactory, Notifiable, SoftDeletes; use \OwenIt\Auditing\Auditable; use TwoFactorAuthenticatable; /** * The attributes that are mass assignable. * * @var list */ protected $appends = ['setup_status']; protected $auditExclude = ['password', 'remember_token', 'two_factor_secret']; protected $fillable = [ 'name', 'email', 'password', 'role_id', 'is_system', 'must_change_password', 'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_setup_completed_at', 'email_verified_at', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password', 'remember_token', 'two_factor_secret', 'two_factor_recovery_codes', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'role_id' => 'integer', 'must_change_password' => 'boolean', 'two_factor_setup_completed_at' => 'datetime', 'two_factor_confirmed_at' => 'datetime', 'is_system' => 'boolean', 'anonymized_at' => 'datetime', ]; } /** * Ruolo applicativo dell'utente. * * @return BelongsTo */ public function role(): BelongsTo { return $this->belongsTo(UserRole::class, 'role_id'); } /** * Storico delle affiliazioni (incarichi) di questo utente. * * @return HasMany */ public function affiliations(): HasMany { return $this->hasMany(UserAffiliation::class); } /** * Send the password reset notification. */ public function sendPasswordResetNotification($token) { $this->notify(new ResetPasswordNotification($token)); } public function getSetupStatusAttribute(): string { if ($this->must_change_password) { return 'password_required'; } if (is_null($this->two_factor_setup_completed_at)) { return '2fa_setup_required'; } return 'complete'; } }