Persiapan hosting: config DB, perbaikan role, fix redirect

This commit is contained in:
Athallah Ghathfan Aqila
2026-06-13 13:56:43 +07:00
parent e3d7750f11
commit 46e999a9d0
9 changed files with 255 additions and 26 deletions
+3 -3
View File
@@ -9,7 +9,7 @@ $action = $_POST['action'] ?? $_GET['action'] ?? 'list';
// ── LIST ────────────────────────────────────────────────────────
if ($action === 'list') {
$rows = mysqli_fetch_all(
mysqli_query($conn, "SELECT id, username, nama, created_at FROM users ORDER BY nama"),
mysqli_query($conn, "SELECT id, username, nama, role, created_at FROM users ORDER BY nama"),
MYSQLI_ASSOC
);
echo json_encode(['status' => 'success', 'data' => $rows]);
@@ -27,7 +27,7 @@ if ($action === 'add') {
exit;
}
$role = in_array($_POST['role'] ?? '', ['admin','superadmin']) ? $_POST['role'] : 'admin';
$role = in_array($_POST['role'] ?? '', ['admin','operator']) ? $_POST['role'] : 'operator';
$hash = password_hash($password, PASSWORD_DEFAULT);
$st = mysqli_prepare($conn, "INSERT INTO users (username, password, nama, role) VALUES (?,?,?,?)");
mysqli_stmt_bind_param($st, 'ssss', $username, $hash, $nama, $role);
@@ -46,7 +46,7 @@ if ($action === 'update') {
$id = (int)($_POST['id'] ?? 0);
$nama = trim($_POST['nama'] ?? '');
$pass = $_POST['password'] ?? '';
$role = in_array($_POST['role'] ?? '', ['admin','superadmin']) ? $_POST['role'] : 'admin';
$role = in_array($_POST['role'] ?? '', ['admin','operator']) ? $_POST['role'] : 'operator';
if ($id <= 0 || !$nama) {
echo json_encode(['status' => 'error', 'message' => 'Data tidak valid']);