42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Lists\UserRole;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* Crea l'utente di sistema: riceve i contenuti riassegnati dagli utenti
|
|
* cancellati (flusso GDPR / oblio) e non è eliminabile né accessibile
|
|
* (password casuale, nessun login previsto). Idempotente.
|
|
*
|
|
* Dipende da UserRoleSeeder (serve il ruolo Admin).
|
|
*/
|
|
class SystemUserSeeder extends Seeder
|
|
{
|
|
public const EMAIL = 'system@dyncoll.local';
|
|
|
|
public function run(): void
|
|
{
|
|
$adminRoleId = UserRole::where('name', UserRole::ADMIN)->value('id');
|
|
|
|
User::updateOrCreate(
|
|
['email' => self::EMAIL],
|
|
[
|
|
'name' => 'Dyncoll System',
|
|
'password' => Hash::make(Str::random(60)),
|
|
'role_id' => $adminRoleId,
|
|
'is_system' => true,
|
|
'must_change_password' => false,
|
|
'email_verified_at' => now(),
|
|
'two_factor_setup_completed_at' => now(),
|
|
]
|
|
);
|
|
|
|
$this->command?->info('✅ System user ready: '.self::EMAIL);
|
|
}
|
|
}
|