From 19ef71c39fca42059f60bee18d5b3c7476dedb00 Mon Sep 17 00:00:00 2001 From: divyesh000 Date: Fri, 17 May 2024 21:13:22 +0400 Subject: [PATCH] add account deletion confirmation dialog to Profile controller and view --- src/controllers/Profile.php | 30 +++++++++++++++++++++++++++--- src/views/Profile.php | 11 +++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/controllers/Profile.php b/src/controllers/Profile.php index f7eca130..37a9897c 100644 --- a/src/controllers/Profile.php +++ b/src/controllers/Profile.php @@ -22,6 +22,7 @@ public function __construct() $this->signed_client = null; $this->view_data['errors'] = []; $this->view_data['client'] = null; + $this->view_data['confirmation_message'] = false; } private function handleLogOut(): void @@ -39,9 +40,31 @@ private function handleLogOut(): void private function handleAccountDeletion(): void { - // delete user account if delete button clicked - $this->signed_client->deleteUser(); - $this->handleLogOut(); + // Display confirmation message + $confirmation_message = "Are you sure you want to delete your account? This action is irreversible."; + $this->view_data['confirmation_message'] = $confirmation_message; + + // Check if the deletion confirmation has been submitted + if (isset($_POST['confirm_delete'])) { + // Perform account deletion + $this->signed_client->deleteUser(); + $this->handleLogOut(); + return; + } + + // Check if cancel button is clicked + if (isset($_POST['cancel_delete'])) { + Utility::redirect('profile'); + return; + } + + // Render the view with the confirmation message + $this->view( + 'Profile', + $this->view_data, + 'Profile', + enableIndexing: false + ); } /** @@ -182,6 +205,7 @@ public function index(): void // delete user account if delete button clicked if (isset($_GET['account_delete_submit'])) { + $this->view_data['confirmation_message'] = true; $this->handleAccountDeletion(); return; } diff --git a/src/views/Profile.php b/src/views/Profile.php index 10d5ad12..0f6142e9 100644 --- a/src/views/Profile.php +++ b/src/views/Profile.php @@ -162,6 +162,7 @@
+ @@ -203,3 +204,13 @@ function openTab(evt, tabName) { +> +
+

Deleting your account!!

+


+
+ + +
+
+
\ No newline at end of file