feat: tambah profil akun dan ganti password
Tambahkan halaman /dashboard/profile beserta API ganti password untuk user yang sedang login. Rapikan AuthSeeder agar idempotent dan bisa ambil admin email/password dari env.
This commit is contained in:
@@ -15,21 +15,37 @@ class AuthSeeder extends Seeder
|
||||
['role_code' => 'GURU_MAPEL', 'role_name' => 'Guru Mata Pelajaran'],
|
||||
['role_code' => 'ORANG_TUA', 'role_name' => 'Orang Tua'],
|
||||
];
|
||||
$this->db->table('roles')->insertBatch($roles);
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$exists = $this->db->table('roles')->where('role_code', $role['role_code'])->countAllResults();
|
||||
if ($exists === 0) {
|
||||
$this->db->table('roles')->insert($role);
|
||||
}
|
||||
}
|
||||
|
||||
$adminEmail = env('ADMIN_EMAIL', 'admin@example.com');
|
||||
$adminPassword = env('ADMIN_PASSWORD', 'admin123');
|
||||
|
||||
$userExists = $this->db->table('users')->where('email', $adminEmail)->countAllResults();
|
||||
if ($userExists > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->db->table('users')->insert([
|
||||
'name' => 'Admin',
|
||||
'email' => 'admin@example.com',
|
||||
'password_hash' => password_hash('admin123', PASSWORD_DEFAULT),
|
||||
'email' => $adminEmail,
|
||||
'password_hash' => password_hash($adminPassword, PASSWORD_DEFAULT),
|
||||
'is_active' => 1,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
$adminId = $this->db->insertID();
|
||||
$adminRoleId = $this->db->table('roles')->where('role_code', 'ADMIN')->get()->getRow()->id;
|
||||
$this->db->table('user_roles')->insert([
|
||||
'user_id' => $adminId,
|
||||
'role_id' => $adminRoleId,
|
||||
]);
|
||||
$adminRole = $this->db->table('roles')->where('role_code', 'ADMIN')->get()->getRow();
|
||||
if ($adminRole) {
|
||||
$this->db->table('user_roles')->insert([
|
||||
'user_id' => $adminId,
|
||||
'role_id' => $adminRole->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user