From 6ff615a270693af19d3fed92e7c710f00456b317 Mon Sep 17 00:00:00 2001 From: Kris Date: Tue, 2 Jun 2026 03:17:21 +0000 Subject: [PATCH] Upload files to "config" --- config/auth.php | 52 +++++++++++++++++++++++++++++++++++++++++++++ config/database.php | 23 ++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 config/auth.php create mode 100644 config/database.php diff --git a/config/auth.php b/config/auth.php new file mode 100644 index 0000000..e0c2536 --- /dev/null +++ b/config/auth.php @@ -0,0 +1,52 @@ + false, 'message' => 'Sesi login tidak ditemukan. Silakan login ulang.']); + exit; + } +} + +function role_in(array $roles): bool +{ + return in_array(current_role(), $roles, true); +} + +function api_require_role(array $roles): void +{ + if (!role_in($roles)) { + http_response_code(403); + header('Content-Type: application/json'); + echo json_encode(['success' => false, 'message' => 'Akses ditolak untuk peran pengguna ini.']); + exit; + } +} diff --git a/config/database.php b/config/database.php new file mode 100644 index 0000000..349529a --- /dev/null +++ b/config/database.php @@ -0,0 +1,23 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ] + ); +} catch (PDOException $e) { + http_response_code(500); + die('Koneksi database gagal. Pastikan database sipantas_webgis sudah di-import. Detail: ' . htmlspecialchars($e->getMessage())); +}