92 lines
2.6 KiB
PHP
92 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class SecureDashboardController extends Controller
|
|
{
|
|
/**
|
|
* Dashboard universale che nasconde il tipo di utente
|
|
*/
|
|
public function index()
|
|
{
|
|
$user = Auth::user();
|
|
|
|
if (!$user) {
|
|
return redirect()->route('login');
|
|
}
|
|
|
|
// Determina il template della dashboard in base al ruolo
|
|
// ma usa sempre lo stesso URL base
|
|
$userEmail = $user->email;
|
|
|
|
if ($userEmail === 'superadmin@example.com') {
|
|
return $this->superAdminDashboard();
|
|
} elseif (in_array($userEmail, [
|
|
'admin@vcard.com',
|
|
'sadmin@vcard.com',
|
|
'miki@gmail.com',
|
|
'admin@netgescon.local' // Nuovo admin standard
|
|
]) || $user->hasRole(['admin', 'amministratore'])) {
|
|
return $this->adminDashboard();
|
|
} elseif (in_array($userEmail, [
|
|
'condomino@test.local'
|
|
])) {
|
|
return $this->condominoDashboard();
|
|
}
|
|
|
|
return view('dashboard.guest');
|
|
}
|
|
|
|
private function superAdminDashboard()
|
|
{
|
|
$userRole = 'super-admin';
|
|
$userPermissions = [
|
|
'dashboard' => true,
|
|
'stabili' => true,
|
|
'condomini' => true,
|
|
'tickets' => true,
|
|
'super_admin' => true
|
|
];
|
|
|
|
$stats = [
|
|
'total_users' => \App\Models\User::count(),
|
|
'total_admins' => \App\Models\User::role('admin')->count(),
|
|
'total_condominios' => \App\Models\User::role('condomino')->count(),
|
|
'active_tickets' => 0,
|
|
'stabili_totali' => \App\Models\Stabile::count(),
|
|
'condomini_totali' => 0
|
|
];
|
|
|
|
return view('admin.dashboard', compact('stats', 'userRole', 'userPermissions'));
|
|
}
|
|
|
|
private function adminDashboard()
|
|
{
|
|
$userRole = 'admin';
|
|
$userPermissions = [
|
|
'dashboard' => true,
|
|
'stabili' => true,
|
|
'condomini' => true,
|
|
'tickets' => true,
|
|
'super_admin' => false
|
|
];
|
|
|
|
$stats = [
|
|
'stabili_totali' => \App\Models\Stabile::count(),
|
|
'condomini_totali' => 0,
|
|
'tickets_aperti' => 0,
|
|
'bilancio_attivo' => 0
|
|
];
|
|
|
|
return view('admin.dashboard', compact('stats', 'userRole', 'userPermissions'));
|
|
}
|
|
|
|
private function condominoDashboard()
|
|
{
|
|
return view('condomino.dashboard');
|
|
}
|
|
}
|