Skip to content

Commit

Permalink
feat: export subscriptions as csv
Browse files Browse the repository at this point in the history
feat: export subscriptions as json
feat: user can delete their own account
  • Loading branch information
Miguel Ribeiro committed Jul 19, 2024
1 parent ed0eb4b commit c7675bc
Show file tree
Hide file tree
Showing 38 changed files with 445 additions and 13 deletions.
124 changes: 124 additions & 0 deletions endpoints/settings/deleteaccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

require_once '../../includes/connect_endpoint.php';

if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
die(json_encode([
"success" => false,
"message" => translate('session_expired', $i18n)
]));
}

if ($_SERVER["REQUEST_METHOD"] === "POST") {

$postData = file_get_contents("php://input");
$data = json_decode($postData, true);

$userIdToDelete = $data['userId'];

if ($userIdToDelete == 1 || $userIdToDelete != $userId) {
die(json_encode([
"success" => false,
"message" => translate('error', $i18n)
]));
} else {
// Delete user
$stmt = $db->prepare('DELETE FROM user WHERE id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete subscriptions
$stmt = $db->prepare('DELETE FROM subscriptions WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete settings
$stmt = $db->prepare('DELETE FROM settings WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete fixer
$stmt = $db->prepare('DELETE FROM fixer WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete custom colors
$stmt = $db->prepare('DELETE FROM custom_colors WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete currencies
$stmt = $db->prepare('DELETE FROM currencies WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete categories
$stmt = $db->prepare('DELETE FROM categories WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete household
$stmt = $db->prepare('DELETE FROM household WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete payment methods
$stmt = $db->prepare('DELETE FROM payment_methods WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete email notifications
$stmt = $db->prepare('DELETE FROM email_notifications WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete telegram notifications
$stmt = $db->prepare('DELETE FROM telegram_notifications WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete webhook notifications
$stmt = $db->prepare('DELETE FROM webhook_notifications WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete gotify notifications
$stmt = $db->prepare('DELETE FROM gotify_notifications WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete pushover notifications
$stmt = $db->prepare('DELETE FROM pushover_notifications WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Dele notification settings
$stmt = $db->prepare('DELETE FROM notification_settings WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete last exchange update
$stmt = $db->prepare('DELETE FROM last_exchange_update WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

// Delete email verification
$stmt = $db->prepare('DELETE FROM email_verification WHERE user_id = :id');
$stmt->bindValue(':id', $userIdToDelete, SQLITE3_INTEGER);
$result = $stmt->execute();

die(json_encode([
"success" => true,
"message" => translate('success', $i18n)
]));

}

} else {
die(json_encode([
"success" => false,
"message" => translate('error', $i18n)
]));
}

?>
44 changes: 44 additions & 0 deletions endpoints/subscriptions/export.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
require_once '../../includes/connect_endpoint.php';

if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
die(json_encode([
"success" => false,
"message" => translate('session_expired', $i18n)
]));
}

require_once '../../includes/getdbkeys.php';

$subscriptions = array();

$query = "SELECT * FROM subscriptions WHERE user_id = :userId";
$stmt = $db->prepare($query);
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
$result = $stmt->execute();

while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$subscriptionDetails = array(
'Name' => str_replace(',', '', $row['name']),
'Next Payment' => $row['next_payment'],
'Categpry' => str_replace(',', '', $categories[$row['category_id']]['name']),
'Payment Method' => str_replace(',', '', $payment_methods[$row['payment_method_id']]['name']),
'Paid By' => str_replace(',', '', $members[$row['payer_user_id']]['name']),
'Price' => $currencies[$row['currency_id']]['symbol'] . $row['price'],
'Notes' => str_replace(',', '', $row['notes']),
'URL' => $row['url'],
'State' => $row['inactive'] ? 'Disabled' : 'Enabled',
'Notifications' => $row['notify'] ? 'Enabled' : 'Disabled',
'Cancellation Date' => $row['cancellation_date']
);

$subscriptions[] = $subscriptionDetails;
}

die(json_encode([
"success" => true,
"subscriptions" => $subscriptions
]));


?>
7 changes: 7 additions & 0 deletions includes/i18n/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Backup",
"restore" => "Wiederherstellen",
"restore_info" => "Durch die Wiederherstellung der Datenbank werden alle aktuellen Daten überschrieben. Nach der Wiederherstellung werden Sie abgemeldet.",
"account" => "Konto",
"export_subscriptions" => "Abonnements exportieren",
"export_as_json" => "Als JSON exportieren",
"export_as_csv" => "Als CSV exportieren",
"danger_zone" => "Gefahrenzone",
"delete_account" => "Konto löschen",
"delete_account_info" => "Mit dem Löschen Ihres Kontos werden auch alle Ihre Abonnements und Einstellungen gelöscht.",
// Filters menu
"filter" => "Filter",
"clear" => "Leeren",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Αντίγραφο ασφαλείας",
"restore" => "Επαναφορά",
"restore_info" => "Η επαναφορά της βάσης δεδομένων θα ακυρώσει όλα τα τρέχοντα δεδομένα. Μετά την επαναφορά θα αποσυνδεθείτε.",
"account" => "Λογαριασμός",
"export_subscriptions" => "Εξαγωγή συνδρομών",
"export_as_json" => "Εξαγωγή ως JSON",
"export_as_csv" => "Εξαγωγή ως CSV",
"danger_zone" => "Ζώνη κινδύνου",
"delete_account" => "Διαγραφή λογαριασμού",
"delete_account_info" => "Η διαγραφή του λογαριασμού θα ακυρώσει όλα τα δεδομένα και θα αποσυνδεθείτε. Αυτή η ενέργεια είναι μη αναστρέψιμη.",
// Filters menu
"filter" => "Φίλτρο",
"clear" => "Καθαρισμός",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Backup",
"restore" => "Restore",
"restore_info" => "Restoring the database will override all current data. You will be signed out after the restore.",
"account" => "Account",
"export_subscriptions" => "Export Subscriptions",
"export_as_json" => "Export as JSON",
"export_as_csv" => "Export as CSV",
"danger_zone" => "Danger Zone",
"delete_account" => "Delete Account",
"delete_account_info" => "Deleting your account will also delete all your subscriptions and settings.",
// Filters menu
"filter" => "Filter",
"clear" => "Clear",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Copia de Seguridad",
"restore" => "Restaurar",
"restore_info" => "La restauración de la base de datos anulará todos los datos actuales. Se cerrará la sesión después de la restauración.",
"account" => "Cuenta",
"export_subscriptions" => "Exportar suscripciones",
"export_as_json" => "Exportar como JSON",
"export_as_csv" => "Exportar como CSV",
"danger_zone" => "Zona de peligro",
"delete_account" => "Eliminar cuenta",
"delete_account_info" => "Al eliminar tu cuenta también se eliminarán todas tus suscripciones y configuraciones.",
// Filters menu
"filter" => "Filtrar",
"clear" => "Limpiar",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Sauvegarde",
"restore" => "Restauration",
"restore_info" => "La restauration de la base de données annulera toutes les données actuelles. Vous serez déconnecté après la restauration.",
"account" => "Compte",
"export_subscriptions" => "Exporter les abonnements",
"export_as_json" => "Exporter en JSON",
"export_as_csv" => "Exporter en CSV",
"danger_zone" => "Zone de danger",
"delete_account" => "Supprimer le compte",
"delete_account_info" => "La suppression de votre compte entraînera également la suppression de tous vos abonnements et paramètres.",
// Menu des filtes
"filter" => "Filtre",
"clear" => "Effacer",
Expand Down
8 changes: 8 additions & 0 deletions includes/i18n/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@
"backup" => 'Backup',
"restore" => 'Ripristina',
"restore_info" => "Il ripristino del database annullerà tutti i dati correnti. Al termine del ripristino, l'utente verrà disconnesso.",
"account" => "Account",
"export_subscriptions" => "Esporta abbonamenti",
"export_as_json" => "Esporta come JSON",
"export_as_csv" => "Esporta come CSV",
"danger_zone" => "Zona di pericolo",
"delete_account" => "Elimina account",
"delete_account_info" => "L'eliminazione del vostro account cancellerà anche tutte le vostre sottoscrizioni e impostazioni.",

// Filters
'filter' => 'Filtra',
'clear' => 'Pulisci',
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/ko.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@
"backup" => "백업",
"restore" => "복구",
"restore_info" => "데이터베이스를 복구하면 현재 데이터를 모두 덮어씁니다. 복구 후 로그아웃됩니다.",
"account" => "계정",
"export_subscriptions" => "구독 내보내기",
"export_as_json" => "JSON으로 내보내기",
"export_as_csv" => "CSV로 내보내기",
"danger_zone" => "위험 구역",
"delete_account" => "계정 삭제",
"delete_account_info" => "계정을 삭제하면 모든 구독과 설정도 함께 삭제됩니다.",
// Filters menu
"filter" => "필터",
"clear" => "초기화",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/pl.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Kopia zapasowa",
"restore" => "Przywróć",
"restore_info" => "Przywrócenie bazy danych zastąpi wszystkie bieżące dane. Po przywróceniu zostaniesz wylogowany.",
"account" => "Konto",
"export_subscriptions" => "Eksportuj subskrypcje",
"export_as_json" => "Eksportuj jako JSON",
"export_as_csv" => "Eksportuj jako CSV",
"danger_zone" => "Strefa zagrożenia",
"delete_account" => "Usuń konto",
"delete_account_info" => "Usunięcie konta spowoduje również usunięcie wszystkich subskrypcji i ustawień.",
// Filters menu
"filter" => "Filtr",
"clear" => "Wyczyść",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/pt.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Backup",
"restore" => "Restauro",
"restore_info" => "O restauro da base de dados apagará todos os dados actuais. A sua sessão irá terminar após o restauro.",
"account" => "Conta",
"export_subscriptions" => "Exportar Subscrições",
"export_as_json" => "Exportar como JSON",
"export_as_csv" => "Exportar como CSV",
"danger_zone" => "Zona de Perigo",
"delete_account" => "Eliminar Conta",
"delete_account_info" => "A eliminação da sua conta também eliminará todas as suas subscrições e definições.",
// Filters menu
"filter" => "Filtro",
"clear" => "Limpar",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/pt_br.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Backup",
"restore" => "Restaurar",
"restore_info" => "A restauração do banco de dados substituirá todos os dados atuais. Você será desconectado após a restauração.",
"account" => "Conta",
"export_subscriptions" => "Exportar assinaturas",
"export_as_json" => "Exportar como JSON",
"export_as_csv" => "Exportar como CSV",
"danger_zone" => "Zona de perigo",
"delete_account" => "Excluir conta",
"delete_account_info" => "Excluir sua conta também excluirá todas as assinaturas e configurações.",
// Filters menu
"filter" => "Filtrar",
"clear" => "Limpar",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/ru.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Резервное копирование",
"restore" => "Восстановление",
"restore_info" => "Восстановление базы данных отменит все текущие данные. После восстановления вы выйдете из системы.",
"account" => "Учетная запись",
"export_subscriptions" => "Экспорт подписок",
"export_as_json" => "Экспорт в JSON",
"export_as_csv" => "Экспорт в CSV",
"danger_zone" => "Опасная зона",
"delete_account" => "Удалить учетную запись",
"delete_account_info" => "При удалении аккаунта также будут удалены все ваши подписки и настройки.",
// Filters menu
"filter" => "Фильтр",
"clear" => "Очистить",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/sr.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Бекап",
"restore" => "Ресторе",
"restore_info" => "Враћање базе података ће заменити све тренутне податке. Бићете одјављени након враћања.",
"account" => "Налог",
"export_subscriptions" => "Извоз претплата",
"export_as_json" => "Извоз као JSON",
"export_as_csv" => "Извоз као CSV",
"danger_zone" => "Зона опасности",
"delete_account" => "Обриши налог",
"delete_account_info" => "Брисање налога ће обрисати све ваше податке, укључујући претплате, подешавања и чланове домаћинства.",
// Мени са филтерима
"filter" => "Филтер",
"clear" => "Очисти",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/sr_lat.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Backup",
"restore" => "Restore",
"restore_info" => "Vraćanje baze podataka će zameniti sve trenutne podatke. Bićete odjavljeni nakon vraćanja.",
"account" => "Nalog",
"export_subscriptions" => "Izvezi pretplate",
"export_as_json" => "Izvezi kao JSON",
"export_as_csv" => "Izvezi kao CSV",
"danger_zone" => "Opasna zona",
"delete_account" => "Izbriši nalog",
"delete_account_info" => "Brisanjem naloga izbrisaćete sve podatke, uključujući pretplate, podešavanja, članove domaćinstva i načine plaćanja.",
// Meni sa filterima
"filter" => "Filter",
"clear" => "Očisti",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/tr.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "Yedekle",
"restore" => "Geri Yükle",
"restore_info" => "Veritabanının geri yüklenmesi tüm mevcut verileri geçersiz kılacaktır. Geri yüklemeden sonra oturumunuz kapatılacaktır.",
"account" => "Hesap",
"export_subscriptions" => "Abonelikleri dışa aktar",
"export_as_json" => "JSON olarak dışa aktar",
"export_as_csv" => "CSV olarak dışa aktar",
"danger_zone" => "Tehlikeli Bölge",
"delete_account" => "Hesabı Sil",
"delete_account_info" => "Hesabınızı sildiğinizde tüm abonelikleriniz ve ayarlarınız da silinecektir.",
// Filters menu
"filter" => "Filtre",
"clear" => "Temizle",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/zh_cn.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@
"backup" => "备份",
"restore" => "恢复",
"restore_info" => "还原数据库将覆盖所有当前数据。还原后,您将退出登录。",
"account" => "账户",
"export_subscriptions" => "导出订阅",
"export_as_json" => "导出为 JSON",
"export_as_csv" => "导出为 CSV",
"danger_zone" => "危险区",
"delete_account" => "删除账户",
"delete_account_info" => "删除账户将删除所有数据,包括订阅、设置和家庭成员。此操作不可逆。",
// Filters menu
"filter" => "筛选",
"clear" => "清除",
Expand Down
7 changes: 7 additions & 0 deletions includes/i18n/zh_tw.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
"backup" => "備份",
"restore" => "還原",
"restore_info" => "復原資料庫將覆蓋所有目前資料。 恢復後您將被註銷。",
"account" => "帳戶",
"export_subscriptions" => "匯出訂閱",
"export_as_json" => "匯出為 JSON",
"export_as_csv" => "匯出為 CSV",
"danger_zone" => "危險區域",
"delete_account" => "刪除帳戶",
"delete_account_info" => "刪除帳戶將刪除所有訂閱和設定。 此操作無法撤銷。",
// Filters menu
"filter" => "篩選",
"clear" => "清除",
Expand Down
Loading

0 comments on commit c7675bc

Please sign in to comment.