diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php index 53c527d..795d460 100644 --- a/application/controllers/ServicesController.php +++ b/application/controllers/ServicesController.php @@ -325,14 +325,10 @@ class ServicesController extends BaseController if (!$user) { // Crea utente SSO (senza password — accede solo via token) - $parts = explode(' ', $name, 2); - $firstName = $parts[0] ?? $email; - $lastName = $parts[1] ?? ''; - Database::query( - 'INSERT INTO users (email, password_hash, first_name, last_name, role, status) - VALUES (?, ?, ?, ?, ?, "active")', - [$email, '', $firstName, $lastName, $role] + 'INSERT INTO users (email, password_hash, full_name, role, is_active) + VALUES (?, ?, ?, ?, 1)', + [$email, '', $name ?: $email, $role] ); $userId = (int) Database::lastInsertId(); } else { @@ -525,13 +521,14 @@ class ServicesController extends BaseController $ragioneSociale = trim($company['ragione_sociale'] ?? ''); $partitaIva = preg_replace('/[^0-9]/', '', $company['partita_iva'] ?? ''); $adminEmail = trim($admin['email'] ?? ''); - $adminFirst = trim($admin['first_name'] ?? ''); - $adminLast = trim($admin['last_name'] ?? ''); + // Supporta sia full_name che first_name+last_name + $adminFullName = trim($admin['full_name'] + ?? trim(($admin['first_name'] ?? '') . ' ' . ($admin['last_name'] ?? ''))); if (!$ragioneSociale) $this->jsonError('company.ragione_sociale obbligatorio', 400, 'MISSING_FIELD'); if (strlen($partitaIva) !== 11) $this->jsonError('company.partita_iva non valida (11 cifre)', 400, 'INVALID_VAT'); if (!filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) $this->jsonError('admin.email non valida', 400, 'INVALID_EMAIL'); - if (!$adminFirst || !$adminLast) $this->jsonError('admin.first_name e last_name obbligatori', 400, 'MISSING_FIELD'); + if (!$adminFullName) $this->jsonError('admin.full_name obbligatorio', 400, 'MISSING_FIELD'); $db = Database::getInstance(); @@ -603,10 +600,10 @@ class ServicesController extends BaseController $userId = (int) $existingUser['id']; } else { Database::query( - 'INSERT INTO users (email, password_hash, first_name, last_name, role, status, + 'INSERT INTO users (email, password_hash, full_name, role, is_active, phone, job_title, must_change_password) - VALUES (?,?,?,?,\'super_admin\',\'active\',?,?,1)', - [$adminEmail, $passwordHash, $adminFirst, $adminLast, + VALUES (?,?,?,\'org_admin\',1,?,?,1)', + [$adminEmail, $passwordHash, $adminFullName, $admin['phone'] ?? null, $admin['title'] ?? null] ); $userId = (int) Database::lastInsertId(); diff --git a/simulate-nis2.php b/simulate-nis2.php index c4ca180..6eb1eb4 100644 --- a/simulate-nis2.php +++ b/simulate-nis2.php @@ -196,19 +196,17 @@ function ensureUser(string $firstName, string $lastName, string $email, string $ // Registrazione $regRes = api('POST', '/auth/register', [ - 'first_name' => $firstName, - 'last_name' => $lastName, - 'email' => DEMO_EMAIL !== $email ? DEMO_EMAIL : $email, - 'password' => $password, - 'role' => $role, + 'full_name' => trim("$firstName $lastName"), + 'email' => DEMO_EMAIL !== $email ? DEMO_EMAIL : $email, + 'password' => $password, + 'role' => $role, ]); // Override email per demo (sempre DEMO_EMAIL ma tracking per slug) $regRes2 = api('POST', '/auth/register', [ - 'first_name' => $firstName, - 'last_name' => $lastName, - 'email' => $email, - 'password' => $password, - 'role' => $role, + 'full_name' => trim("$firstName $lastName"), + 'email' => $email, + 'password' => $password, + 'role' => $role, ]); if (!empty($regRes2['data']['access_token'])) { $jwt = $regRes2['data']['access_token'];