refactor: completely remove hardcoded credential strings from all seeders, bind purely to config auth and env
This commit is contained in:
@@ -50,53 +50,25 @@ class DatabaseSeeder extends Seeder
|
||||
// 2. Seed RBAC Roles & Permissions Matrix
|
||||
$this->call(RolePermissionSeeder::class);
|
||||
|
||||
// 3. Seed 4 Akun Utama Administrator Sistem (Kredensial dinamis dari config/auth.php & .env)
|
||||
// 3. Seed 4 Akun Utama Administrator Sistem (Murni dibaca dari config/auth.php & .env)
|
||||
$coreAdmins = [
|
||||
[
|
||||
'role' => 'super_admin',
|
||||
'config' => config('auth.superadmin', [
|
||||
'name' => 'Super Administrator',
|
||||
'username' => 'superadmin',
|
||||
'email' => '[email protected]',
|
||||
'password' => 'password',
|
||||
]),
|
||||
],
|
||||
[
|
||||
'role' => 'hse_admin',
|
||||
'config' => config('auth.hse_admin', [
|
||||
'name' => 'Admin HSE',
|
||||
'username' => '1185',
|
||||
'email' => '[email protected]',
|
||||
'password' => 'password',
|
||||
]),
|
||||
],
|
||||
[
|
||||
'role' => 'qma_admin',
|
||||
'config' => config('auth.qma_admin', [
|
||||
'name' => 'Admin QMA',
|
||||
'username' => '1171',
|
||||
'email' => '[email protected]',
|
||||
'password' => 'password',
|
||||
]),
|
||||
],
|
||||
[
|
||||
'role' => 'pg_admin',
|
||||
'config' => config('auth.pg_admin', [
|
||||
'name' => 'Admin PG',
|
||||
'username' => 'AdminPG',
|
||||
'email' => '[email protected]',
|
||||
'password' => 'password',
|
||||
]),
|
||||
],
|
||||
['role' => 'super_admin', 'config' => config('auth.superadmin')],
|
||||
['role' => 'hse_admin', 'config' => config('auth.hse_admin')],
|
||||
['role' => 'qma_admin', 'config' => config('auth.qma_admin')],
|
||||
['role' => 'pg_admin', 'config' => config('auth.pg_admin')],
|
||||
];
|
||||
|
||||
foreach ($coreAdmins as $adminData) {
|
||||
$conf = $adminData['config'];
|
||||
if (!$conf || empty($conf['username']) || empty($conf['password'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = User::firstOrCreate([
|
||||
'username' => $conf['username'],
|
||||
], [
|
||||
'name' => $conf['name'],
|
||||
'email' => $conf['email'],
|
||||
'name' => $conf['name'] ?? ucwords(str_replace('_', ' ', $adminData['role'])),
|
||||
'email' => $conf['email'] ?? ($conf['username'] . '@kmh.co.id'),
|
||||
'password' => Hash::make($conf['password']),
|
||||
'role' => $adminData['role'],
|
||||
]);
|
||||
|
||||
@@ -78,19 +78,14 @@ class RolePermissionSeeder extends Seeder
|
||||
$role->syncPermissions($perms);
|
||||
}
|
||||
|
||||
// 4. Buat Akun Default Super Admin (Mengambil dari config/auth.php & .env)
|
||||
$superAdminConfig = config('auth.superadmin', [
|
||||
'name' => 'Super Administrator',
|
||||
'username' => 'superadmin',
|
||||
'email' => '[email protected]',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
// 4. Buat Akun Default Super Admin (Murni dibaca dari config/auth.php & .env)
|
||||
$superAdminConfig = config('auth.superadmin');
|
||||
if ($superAdminConfig && !empty($superAdminConfig['username']) && !empty($superAdminConfig['password'])) {
|
||||
$superAdmin = User::firstOrCreate(
|
||||
['username' => $superAdminConfig['username']],
|
||||
[
|
||||
'name' => $superAdminConfig['name'],
|
||||
'email' => $superAdminConfig['email'],
|
||||
'name' => $superAdminConfig['name'] ?? 'Super Administrator',
|
||||
'email' => $superAdminConfig['email'] ?? '[email protected]',
|
||||
'password' => Hash::make($superAdminConfig['password']),
|
||||
'role' => 'super_admin',
|
||||
]
|
||||
@@ -99,6 +94,7 @@ class RolePermissionSeeder extends Seeder
|
||||
if (!$superAdmin->hasRole('super_admin')) {
|
||||
$superAdmin->assignRole('super_admin');
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Sinkronisasi Akun Existing ke Spatie Roles
|
||||
$existingUsers = User::all();
|
||||
|
||||
@@ -13,18 +13,13 @@ class SuperAdminSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$superAdminConfig = config('auth.superadmin', [
|
||||
'name' => 'Super Administrator',
|
||||
'username' => 'superadmin',
|
||||
'email' => '[email protected]',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$superAdminConfig = config('auth.superadmin');
|
||||
if ($superAdminConfig && !empty($superAdminConfig['username']) && !empty($superAdminConfig['password'])) {
|
||||
$superAdmin = User::updateOrCreate(
|
||||
['username' => $superAdminConfig['username']],
|
||||
[
|
||||
'name' => $superAdminConfig['name'],
|
||||
'email' => $superAdminConfig['email'],
|
||||
'name' => $superAdminConfig['name'] ?? 'Super Administrator',
|
||||
'email' => $superAdminConfig['email'] ?? '[email protected]',
|
||||
'password' => Hash::make($superAdminConfig['password']),
|
||||
'role' => 'super_admin',
|
||||
]
|
||||
@@ -35,3 +30,4 @@ class SuperAdminSeeder extends Seeder
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user