From 19ef71c39fca42059f60bee18d5b3c7476dedb00 Mon Sep 17 00:00:00 2001 From: divyesh000 Date: Fri, 17 May 2024 21:13:22 +0400 Subject: [PATCH 1/2] 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 From ac0928f3f723407c2920f7928f3fd6bcb2f6d16e Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Sun, 19 May 2024 14:28:18 +0400 Subject: [PATCH 2/2] insert confirmation dialog in html only during deletion, rename view variable to be more meaningful, improve dialog ui --- src/controllers/Profile.php | 7 ++----- src/views/Profile.php | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/controllers/Profile.php b/src/controllers/Profile.php index 37a9897c..be9e8e00 100644 --- a/src/controllers/Profile.php +++ b/src/controllers/Profile.php @@ -22,7 +22,7 @@ public function __construct() $this->signed_client = null; $this->view_data['errors'] = []; $this->view_data['client'] = null; - $this->view_data['confirmation_message'] = false; + $this->view_data['show_account_deletion_confirmation'] = false; } private function handleLogOut(): void @@ -40,9 +40,7 @@ private function handleLogOut(): void private function handleAccountDeletion(): void { - // 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; + $this->view_data['show_account_deletion_confirmation'] = true; // Check if the deletion confirmation has been submitted if (isset($_POST['confirm_delete'])) { @@ -205,7 +203,6 @@ 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 0f6142e9..54d94253 100644 --- a/src/views/Profile.php +++ b/src/views/Profile.php @@ -6,6 +6,7 @@ * The following attributes are defined in controllers/Profile.php * * @var $client Client signed in client + * @var $show_account_deletion_confirmation bool Whether to display a confirmation dialog for account deletion * @var $orders array array of orders */ @@ -203,14 +204,19 @@ function openTab(evt, tabName) { - -> -
-

Deleting your account!!

-


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

Deleting your account!

+

Are you sure you want to delete your account? This action is irreversible.

+
+
+ + +
+
+
+
+