-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
38 changed files
with
445 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
])); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
])); | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.