$tokenData['expires_at']) { unset($tokens[$token]); file_put_contents($manifestPath, json_encode($tokens, JSON_PRETTY_PRINT)); header("Location: 404.php"); exit; } $id_occupant = $tokenData['id_occupant']; // Add password columns to occupant if they don't exist yet try { $pdo->exec("ALTER TABLE occupant ADD COLUMN password VARCHAR(255) NULL AFTER no_hp"); } catch(PDOException $e) {} try { $pdo->exec("ALTER TABLE occupant ADD COLUMN password_enc VARCHAR(255) NULL AFTER password"); } catch(PDOException $e) {} // Ambil data occupant $stmt = $pdo->prepare("SELECT name, password_enc FROM occupant WHERE id_occupant = ?"); $stmt->execute([$id_occupant]); $occupant = $stmt->fetch(PDO::FETCH_ASSOC); if (!$occupant) { header("Location: 404.php"); exit; } // Proses jika form disubmit via AJAX if ($_SERVER['REQUEST_METHOD'] === 'POST') { header('Content-Type: application/json'); $action = isset($_POST['action']) ? $_POST['action'] : ''; if ($action === 'verify_pin') { $pin = isset($_POST['pin']) ? trim($_POST['pin']) : ''; if (empty($pin)) { echo json_encode(["status" => "error", "message" => "PIN is required."]); exit; } $stmt = $pdo->prepare("SELECT pin FROM occupant WHERE id_occupant = ?"); $stmt->execute([$id_occupant]); $data = $stmt->fetch(PDO::FETCH_ASSOC); if ($data && $data['pin'] === $pin) { echo json_encode(["status" => "success", "message" => "PIN Valid. Please enter a new password."]); } else { echo json_encode(["status" => "error", "message" => "PIN is invalid!"]); } exit; } if ($action === 'reset_password') { $password = isset($_POST['password']) ? $_POST['password'] : ''; $confirm_password = isset($_POST['confirm_password']) ? $_POST['confirm_password'] : ''; if (empty($password) || empty($confirm_password)) { echo json_encode(["status" => "error", "message" => "All fields are required."]); exit; } if ($password !== $confirm_password) { echo json_encode(["status" => "error", "message" => "Passwords do not match."]); exit; } $password_hash = password_hash($password, PASSWORD_DEFAULT); try { $stmt = $pdo->prepare("UPDATE occupant SET password = ?, password_enc = ? WHERE id_occupant = ?"); if ($stmt->execute([$password_hash, $password, $id_occupant])) { // Edit Telegram Message to disable the inline button if (isset($tokenData['msg_id'])) { $botToken = "8184881871:AAFOz6uzIgxE7rk3WttcKKrr0DtcNGIt-Ho"; $chatId = $occupant['telegram_id'] ?? $tokenData['id_occupant']; // We need actual telegram_id. $tstmt = $pdo->prepare("SELECT telegram_id FROM occupant WHERE id_occupant = ?"); $tstmt->execute([$id_occupant]); $tdata = $tstmt->fetch(PDO::FETCH_ASSOC); if ($tdata && $tdata['telegram_id']) { $chatId = $tdata['telegram_id']; @file_get_contents("https://api.telegram.org/bot$botToken/deleteMessage?chat_id=$chatId&message_id={$tokenData['msg_id']}"); if (isset($tokenData['user_msg_id'])) { @file_get_contents("https://api.telegram.org/bot$botToken/deleteMessage?chat_id=$chatId&message_id={$tokenData['user_msg_id']}"); } // Send success message that auto-deletes after 5 seconds with live countdown $successLabel = "✅ Data saved successfully"; $successText = "" . $successLabel . ""; $successPost = ['chat_id' => $chatId, 'text' => $successText, 'parse_mode' => 'HTML']; $res = @file_get_contents("https://api.telegram.org/bot$botToken/sendMessage?" . http_build_query($successPost)); $resData2 = json_decode($res, true); if (isset($resData2['result']['message_id'])) { $successMsgId = $resData2['result']['message_id']; runBackground(__DIR__ . '/auto_delete_quick.php', [$chatId, $successMsgId, $successLabel]); } } } // Hapus token karena sudah digunakan (single-use) unset($tokens[$token]); file_put_contents($manifestPath, json_encode($tokens, JSON_PRETTY_PRINT)); echo json_encode(["status" => "success", "message" => "Password updated successfully!"]); } else { echo json_encode(["status" => "error", "message" => "Failed to save password."]); } } catch (PDOException $e) { echo json_encode(["status" => "error", "message" => "Database Error: " . $e->getMessage()]); } exit; } } ?>
Enter the 6-Digit PIN for the account
= htmlspecialchars($occupant['name']) ?>