refactor: make poverty map public and remove redundant user authentication requirements

This commit is contained in:
z0rayy
2026-06-10 16:29:04 +07:00
parent bae7c0b294
commit 24e75d6377
6 changed files with 37 additions and 147 deletions
-53
View File
@@ -1,53 +0,0 @@
<?php
header('Content-Type: application/json');
require 'koneksi.php';
$c = getConnection();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['status' => '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
]);
}