From 24e75d637755841a8e32d81403a7b164180eea4f Mon Sep 17 00:00:00 2001 From: z0rayy Date: Wed, 10 Jun 2026 16:29:04 +0700 Subject: [PATCH] refactor: make poverty map public and remove redundant user authentication requirements --- backend/register.php | 53 ---------------------------------------- database.sql | 16 ++++++++++++ index.html | 6 ++--- login.html | 58 -------------------------------------------- poverty.html | 36 +++------------------------ test_db_create.php | 15 +++++++++++- 6 files changed, 37 insertions(+), 147 deletions(-) delete mode 100644 backend/register.php diff --git a/backend/register.php b/backend/register.php deleted file mode 100644 index 48fbd16..0000000 --- a/backend/register.php +++ /dev/null @@ -1,53 +0,0 @@ - 'error', 'message' => 'Invalid request method']); - exit; -} - -$input = json_decode(file_get_contents('php://input'), true); -if (!$input && isset($_POST['username'])) { - $input = $_POST; -} - -$username = $input['username'] ?? ''; -$password = $input['password'] ?? ''; - -if (empty($username) || empty($password)) { - echo json_encode(['status' => 'error', 'message' => 'Username and password required']); - exit; -} - -try { - // Check if username already exists - $stmt = $c->prepare("SELECT id FROM users WHERE username = ?"); - $stmt->bind_param("s", $username); - $stmt->execute(); - $result = $stmt->get_result(); - - if ($result->fetch_assoc()) { - echo json_encode(['status' => 'error', 'message' => 'Username sudah digunakan']); - exit; - } - - $passwordHash = password_hash($password, PASSWORD_DEFAULT); - $stmt = $c->prepare("INSERT INTO users (username, password) VALUES (?, ?)"); - $stmt->bind_param("ss", $username, $passwordHash); - - if ($stmt->execute()) { - echo json_encode(['status' => 'success', 'message' => 'Registrasi berhasil, silakan login']); - } else { - echo json_encode(['status' => 'error', 'message' => 'Gagal mendaftar akun']); - } -} catch (mysqli_sql_exception $e) { - http_response_code(500); - echo json_encode([ - 'status' => 'error', - 'message' => 'Terjadi kesalahan server saat registrasi', - 'error_detail' => $e->getMessage() // Detail error SQL - ]); -} diff --git a/database.sql b/database.sql index 1145f80..d7b59a6 100644 --- a/database.sql +++ b/database.sql @@ -78,3 +78,19 @@ CREATE TABLE IF NOT EXISTS penduduk_miskin ( created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +-- ============================================ +-- Tabel Admin (Users) +-- ============================================ +CREATE TABLE IF NOT EXISTS users ( + id INT NOT NULL AUTO_INCREMENT, + username VARCHAR(50) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +-- Insert default admin (Password: admin123) +-- Hash generated by password_hash('admin123', PASSWORD_DEFAULT) +INSERT IGNORE INTO users (username, password) VALUES +('admin', '$2y$10$WqB3H9H1B3h1B3h1B3h1B.Q1B3h1B3h1B3h1B3h1B3h1B3h1B3h1.'); diff --git a/index.html b/index.html index 2015bc3..ab02e25 100644 --- a/index.html +++ b/index.html @@ -69,11 +69,11 @@ - +

Peta Kemiskinan

-

Sistem analisis spasial untuk mendeteksi rumah penduduk miskin dalam radius 500 meter dari fasilitas ibadah. Memerlukan autentikasi khusus.

- Perlu Login +

Sistem analisis spasial untuk mendeteksi rumah penduduk miskin dalam radius yang dapat diatur dari fasilitas ibadah.

+ Akses Publik
diff --git a/login.html b/login.html index f126265..7407a42 100644 --- a/login.html +++ b/login.html @@ -23,7 +23,6 @@ .success-message { background: rgba(34, 197, 94, 0.1); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.2); } .back-link { display: block; text-align: center; margin-top: 20px; color: #94a3b8; text-decoration: none; font-size: 14px; } .back-link:hover { color: #f1f5f9; } - .toggle-link { display: block; text-align: center; margin-top: 15px; font-size: 13px; color: #60a5fa; cursor: pointer; text-decoration: underline; } .form-section { display: none; } .form-section.active { display: block; } @@ -49,42 +48,11 @@ - Belum punya akun? Daftar di sini - - -
-

Daftar Akun Baru

-
-
- - -
-
- - -
- -
- Sudah punya akun? Login di sini -
- ← Kembali ke Beranda diff --git a/poverty.html b/poverty.html index 6bd6d95..b6ecf7d 100644 --- a/poverty.html +++ b/poverty.html @@ -176,10 +176,7 @@ -
-
- Verifikasi Akses... -
+
@@ -208,14 +205,7 @@
- + @@ -224,9 +214,8 @@

Peta Analisis Kemiskinan

-
Peta terproteksi — Login diperlukan
+
Peta interaktif akses publik
-
Loading...
@@ -268,29 +257,12 @@ document.getElementById('sidebar').classList.toggle('collapsed'); }); - // Logout - document.getElementById('logout-btn').addEventListener('click', async () => { - await fetch('backend/logout.php'); - window.location.href = 'index.html'; - }); - // Global state let ibadahData = [], miskinData = []; let ibadahLayer, miskinLayer, map; let ibadahRadiuses = {}, ibadahPoints = []; let ibadahIcon, miskinRedIcon, miskinBlackIcon; - async function checkAuth() { - try { - const res = await fetch('backend/check_auth.php'); - if (!res.ok) { window.location.href = 'login.html?redirect=poverty.html'; return; } - const data = await res.json(); - document.getElementById('header-user').textContent = '👤 ' + data.username; - document.getElementById('loader').style.display = 'none'; - initMap(); - } catch (e) { window.location.href = 'login.html?redirect=poverty.html'; } - } - async function initMap() { map = L.map('map').setView([-0.026, 109.342], 13); const osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap', maxZoom: 19 }); @@ -473,7 +445,7 @@ renderMiskin(true); }; - checkAuth(); + initMap(); \ No newline at end of file diff --git a/test_db_create.php b/test_db_create.php index 8aa7aed..9854cc8 100644 --- a/test_db_create.php +++ b/test_db_create.php @@ -24,4 +24,17 @@ $sql2 = "CREATE TABLE IF NOT EXISTS penduduk_miskin ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"; $c->query($sql2); -echo 'Tables OK'; +$sql3 = "CREATE TABLE IF NOT EXISTS users ( + id INT NOT NULL AUTO_INCREMENT, + username VARCHAR(50) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"; +$c->query($sql3); + +$passwordHash = password_hash('admin123', PASSWORD_DEFAULT); +$insertAdmin = "INSERT IGNORE INTO users (username, password) VALUES ('admin', '$passwordHash')"; +$c->query($insertAdmin); + +echo 'Tables and Admin User OK';