feat: implement user registration backend and temporarily disable routing panel in admin interface
This commit is contained in:
+2
-2
@@ -1281,7 +1281,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Routing & Radius Panel (Right) -->
|
||||
<div class="routing-panel">
|
||||
<!-- <div class="routing-panel">
|
||||
<h3>📍 ROUTING & RADIUS</h3>
|
||||
<button class="btn btn-sm" id="btn-nearest-spbu" style="width:100%; background:#2563eb; color:white; border:none; padding:8px; border-radius:6px; cursor:pointer; font-weight:600; font-size:12px; margin-bottom:6px;">📍 Cari SPBU Terdekat</button>
|
||||
<div id="nearest-spbu-result" style="font-size:11px; color:#94a3b8; margin-bottom:10px;"></div>
|
||||
@@ -1292,7 +1292,7 @@
|
||||
<span id="radius-value">500 m</span>
|
||||
<span style="color:#64748b;">(Klik peta)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<!-- Floating "Tambah Data" Toolbar -->
|
||||
<div id="map-add-toolbar" style="
|
||||
|
||||
+18
-11
@@ -3,20 +3,27 @@
|
||||
// koneksi.php — Konfigurasi Database
|
||||
// ============================================
|
||||
|
||||
define('DB_HOST', 'localhost');
|
||||
define('DB_USER', 'root'); // Sesuaikan dengan user MySQL Anda
|
||||
define('DB_PASS', ''); // Sesuaikan dengan password MySQL Anda
|
||||
define('DB_NAME', 'webgis_spbu');
|
||||
define('DB_HOST', getenv('DB_HOST') ?: 'localhost');
|
||||
define('DB_USER', getenv('DB_USER') ?: 'root');
|
||||
define('DB_PASS', getenv('DB_PASS') ?: '');
|
||||
define('DB_NAME', getenv('DB_NAME') ?: 'webgis_spbu');
|
||||
|
||||
// Mengaktifkan exception untuk mysqli agar error bisa ditangkap dengan try-catch
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
|
||||
function getConnection(): mysqli {
|
||||
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
try {
|
||||
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||
$conn->set_charset('utf8mb4');
|
||||
return $conn;
|
||||
} catch (mysqli_sql_exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'message' => 'Koneksi database gagal: ' . $conn->connect_error]);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Koneksi database gagal',
|
||||
'error_detail' => $e->getMessage() // Detail error ini akan muncul di tab Network
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$conn->set_charset('utf8mb4');
|
||||
return $conn;
|
||||
}
|
||||
|
||||
+27
-18
@@ -22,23 +22,32 @@ if (empty($username) || empty($password)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// 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();
|
||||
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']);
|
||||
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
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user