Skip to content

Commit

Permalink
add account deletion confirmation dialog to Profile controller and view
Browse files Browse the repository at this point in the history
  • Loading branch information
Divyeshhhh committed May 17, 2024
1 parent c6ac3b5 commit 19ef71c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/controllers/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
);
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/views/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<form>
<button type="submit" name="account_delete_submit">Delete</button>
</form>

</article>
</div>
</div>
Expand Down Expand Up @@ -203,3 +204,13 @@ function openTab(evt, tabName) {

</script>

<dialog <?= $confirmation_message ? "open" : "" ?>>
<article>
<h3>Deleting your account!! </h3>
<p><?= $confirmation_message ?></p><br>
<form method="post">
<button type="submit" name="confirm_delete">Confirm</button>
<button type="submit" name="cancel_delete">Cancel</button>
</form>
</article>
</dialog>

0 comments on commit 19ef71c

Please sign in to comment.