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
|
// 2. Seed RBAC Roles & Permissions Matrix
|
||||||
$this->call(RolePermissionSeeder::class);
|
$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 = [
|
$coreAdmins = [
|
||||||
[
|
['role' => 'super_admin', 'config' => config('auth.superadmin')],
|
||||||
'role' => 'super_admin',
|
['role' => 'hse_admin', 'config' => config('auth.hse_admin')],
|
||||||
'config' => config('auth.superadmin', [
|
['role' => 'qma_admin', 'config' => config('auth.qma_admin')],
|
||||||
'name' => 'Super Administrator',
|
['role' => 'pg_admin', 'config' => config('auth.pg_admin')],
|
||||||
'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',
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($coreAdmins as $adminData) {
|
foreach ($coreAdmins as $adminData) {
|
||||||
$conf = $adminData['config'];
|
$conf = $adminData['config'];
|
||||||
|
if (!$conf || empty($conf['username']) || empty($conf['password'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$user = User::firstOrCreate([
|
$user = User::firstOrCreate([
|
||||||
'username' => $conf['username'],
|
'username' => $conf['username'],
|
||||||
], [
|
], [
|
||||||
'name' => $conf['name'],
|
'name' => $conf['name'] ?? ucwords(str_replace('_', ' ', $adminData['role'])),
|
||||||
'email' => $conf['email'],
|
'email' => $conf['email'] ?? ($conf['username'] . '@kmh.co.id'),
|
||||||
'password' => Hash::make($conf['password']),
|
'password' => Hash::make($conf['password']),
|
||||||
'role' => $adminData['role'],
|
'role' => $adminData['role'],
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -78,19 +78,14 @@ class RolePermissionSeeder extends Seeder
|
|||||||
$role->syncPermissions($perms);
|
$role->syncPermissions($perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Buat Akun Default Super Admin (Mengambil dari config/auth.php & .env)
|
// 4. Buat Akun Default Super Admin (Murni dibaca dari config/auth.php & .env)
|
||||||
$superAdminConfig = config('auth.superadmin', [
|
$superAdminConfig = config('auth.superadmin');
|
||||||
'name' => 'Super Administrator',
|
if ($superAdminConfig && !empty($superAdminConfig['username']) && !empty($superAdminConfig['password'])) {
|
||||||
'username' => 'superadmin',
|
|
||||||
'email' => '[email protected]',
|
|
||||||
'password' => 'password',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$superAdmin = User::firstOrCreate(
|
$superAdmin = User::firstOrCreate(
|
||||||
['username' => $superAdminConfig['username']],
|
['username' => $superAdminConfig['username']],
|
||||||
[
|
[
|
||||||
'name' => $superAdminConfig['name'],
|
'name' => $superAdminConfig['name'] ?? 'Super Administrator',
|
||||||
'email' => $superAdminConfig['email'],
|
'email' => $superAdminConfig['email'] ?? '[email protected]',
|
||||||
'password' => Hash::make($superAdminConfig['password']),
|
'password' => Hash::make($superAdminConfig['password']),
|
||||||
'role' => 'super_admin',
|
'role' => 'super_admin',
|
||||||
]
|
]
|
||||||
@@ -99,6 +94,7 @@ class RolePermissionSeeder extends Seeder
|
|||||||
if (!$superAdmin->hasRole('super_admin')) {
|
if (!$superAdmin->hasRole('super_admin')) {
|
||||||
$superAdmin->assignRole('super_admin');
|
$superAdmin->assignRole('super_admin');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 5. Sinkronisasi Akun Existing ke Spatie Roles
|
// 5. Sinkronisasi Akun Existing ke Spatie Roles
|
||||||
$existingUsers = User::all();
|
$existingUsers = User::all();
|
||||||
|
|||||||
@@ -13,18 +13,13 @@ class SuperAdminSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$superAdminConfig = config('auth.superadmin', [
|
$superAdminConfig = config('auth.superadmin');
|
||||||
'name' => 'Super Administrator',
|
if ($superAdminConfig && !empty($superAdminConfig['username']) && !empty($superAdminConfig['password'])) {
|
||||||
'username' => 'superadmin',
|
|
||||||
'email' => '[email protected]',
|
|
||||||
'password' => 'password',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$superAdmin = User::updateOrCreate(
|
$superAdmin = User::updateOrCreate(
|
||||||
['username' => $superAdminConfig['username']],
|
['username' => $superAdminConfig['username']],
|
||||||
[
|
[
|
||||||
'name' => $superAdminConfig['name'],
|
'name' => $superAdminConfig['name'] ?? 'Super Administrator',
|
||||||
'email' => $superAdminConfig['email'],
|
'email' => $superAdminConfig['email'] ?? '[email protected]',
|
||||||
'password' => Hash::make($superAdminConfig['password']),
|
'password' => Hash::make($superAdminConfig['password']),
|
||||||
'role' => 'super_admin',
|
'role' => 'super_admin',
|
||||||
]
|
]
|
||||||
@@ -35,3 +30,4 @@ class SuperAdminSeeder extends Seeder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user