From 4778b9dedb1583ba1091da8d55d5ea6bf62f3202 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 21 May 2016 19:50:01 -0400 Subject: Add 'Delete Account' button to user settings form Links to a confirmation page which will require the user's current password to succeed. --- app/view/common/setting.modal.view.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/view/common/setting.modal.view.php b/app/view/common/setting.modal.view.php index e43f723..845f4ed 100644 --- a/app/view/common/setting.modal.view.php +++ b/app/view/common/setting.modal.view.php @@ -107,6 +107,11 @@ +

 

+

 

+ + Delete Account +

 

-- cgit v1.2.3 From 32e4e9606fb2ac95b236913fcc0a98a7ee23bccd Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 21 May 2016 21:44:53 -0400 Subject: Add MVC Deleteacct This will prompt the user for their password if they opt to delete their own account. This is to prevent malicious attempt by others to trick users into having there accounts deleted by way of a XSS attack. --- app/controller/deleteacct.control.php | 28 ++++++++++++++++++++++++++++ app/model/deleteacct.mod.php | 15 +++++++++++++++ app/view/deleteacct/default.view.php | 13 +++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 app/controller/deleteacct.control.php create mode 100644 app/model/deleteacct.mod.php create mode 100644 app/view/deleteacct/default.view.php diff --git a/app/controller/deleteacct.control.php b/app/controller/deleteacct.control.php new file mode 100644 index 0000000..176b7bf --- /dev/null +++ b/app/controller/deleteacct.control.php @@ -0,0 +1,28 @@ +action_default($mod); + } + + function action_default($mod) + { + $mod->deflt(); + include "view/deleteacct/default.view.php"; + } +} + +?> diff --git a/app/model/deleteacct.mod.php b/app/model/deleteacct.mod.php new file mode 100644 index 0000000..ca01a0d --- /dev/null +++ b/app/model/deleteacct.mod.php @@ -0,0 +1,15 @@ + diff --git a/app/view/deleteacct/default.view.php b/app/view/deleteacct/default.view.php new file mode 100644 index 0000000..b078861 --- /dev/null +++ b/app/view/deleteacct/default.view.php @@ -0,0 +1,13 @@ + + + + + + Scrott - Delete user account + + + + + + + -- cgit v1.2.3 From 685c64e3ac98bcf5fc2b17fade4f00726e95b8b0 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 21 May 2016 22:16:18 -0400 Subject: Hook Deleteacct in the Root app controller --- app/controller/root.control.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controller/root.control.php b/app/controller/root.control.php index 7017ada..341fa8a 100644 --- a/app/controller/root.control.php +++ b/app/controller/root.control.php @@ -7,6 +7,7 @@ require_once "controller/except.control.php"; require_once "controller/auth.control.php"; require_once "controller/deauth.control.php"; require_once "controller/dashboard.control.php"; +require_once "controller/deleteacct.control.php"; /* * Root-level controller for Scrott app. This object will delegate the page request to the @@ -65,6 +66,7 @@ class Root extends Controller switch ($argv[0]) { case "logout": $ctrl = new Deauth(); break; + case "deleteaccount": $ctrl = new Deleteacct(); break; default: throw new Exception("The requested path is not valid."); break; -- cgit v1.2.3 From f8f8cd372ca2bb6498d96318c159405db13a9fab Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 22 May 2016 00:24:57 -0400 Subject: Add class constructor to Common model There are two functions that need called in the common model whenever a page is rendered. Rather than requiring all of the base MVC controllers to call them, I am placing them in a constructor for this model class. This constructor should fire automatically (since base mvc models inherit this class), unless base classes define their own constructors. I don't antisipate this happening, however in that case, they would just need to call parent::__construct(). --- app/controller/dashboard.control.php | 2 -- app/model/common.mod.php | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controller/dashboard.control.php b/app/controller/dashboard.control.php index aa1c0bd..4ee4b38 100644 --- a/app/controller/dashboard.control.php +++ b/app/controller/dashboard.control.php @@ -14,8 +14,6 @@ class Dashboard extends Controller function handle($argv) { $mod = new DashboardModel(); - $mod->common_handleFormSubmissions($_REQUEST['input'], $_FILES['attachment']); - $mod->common_deflt(); $this->action_default($mod); } diff --git a/app/model/common.mod.php b/app/model/common.mod.php index 7630dfa..03ed54f 100644 --- a/app/model/common.mod.php +++ b/app/model/common.mod.php @@ -13,6 +13,16 @@ class CommonModel extends MasterModel "image/jpeg" ); + /* + * Constructor + */ + function __construct() + { + parent::__construct(); + $this->common_handleFormSubmissions($_REQUEST['input'], $_FILES['attachment']); + $this->common_deflt(); + } + /* * Default action */ -- cgit v1.2.3 From a99a0afd57a109f581c676b8dd3622dd3e901553 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 22 May 2016 01:59:53 -0400 Subject: Create view for delete account MVC This page prompts for user password before actually deleteing their account. --- app/view/deleteacct/default.view.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/view/deleteacct/default.view.php b/app/view/deleteacct/default.view.php index b078861..de32202 100644 --- a/app/view/deleteacct/default.view.php +++ b/app/view/deleteacct/default.view.php @@ -8,6 +8,30 @@ + +
+
+
Warning: Deleting your user account!
+ +
+
+ +

Are you sure?!

+

Please confirm you want to delete your Scrott account. Type your current password in the box below and click the confirm button

+ +
+ + +
+ + +
+
+
+
+ -- cgit v1.2.3 From 5f99922eb6fbda82da55ccf728eda6add48cb4f1 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 22 May 2016 02:50:17 -0400 Subject: Add function User::getNumAdmins() Function to count the number of admin accounts that exist. This is used to make sure that while deleteing accounts, the number of administrators never drops to zero. --- app/class/user.class.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/class/user.class.php b/app/class/user.class.php index 1d17dfe..07bd0d6 100644 --- a/app/class/user.class.php +++ b/app/class/user.class.php @@ -74,6 +74,16 @@ class User extends Object return $users; } + /* + * Get the number of administrative accounts in the system + */ + function getNumAdmins() + { + $query = "SELECT count(*) as cnt FROM user WHERE admin = 1"; + $results = $this->db->query($query); + return $results[0]['cnt']; + } + /* * Check whether a given username is currently in use */ -- cgit v1.2.3 From c2137095e8b176affa3e97af579a70d394eeb7c1 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 22 May 2016 03:02:33 -0400 Subject: Add action 'delete' to Deleteacct MVC This action will validate the user's password, and make sure you're not removing the last admin, then proceed to delete the current user's account from the database and log them out, for good. --- app/controller/deleteacct.control.php | 18 +++++++++++++++++- app/model/deleteacct.mod.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/app/controller/deleteacct.control.php b/app/controller/deleteacct.control.php index 176b7bf..bd81ec7 100644 --- a/app/controller/deleteacct.control.php +++ b/app/controller/deleteacct.control.php @@ -15,7 +15,17 @@ class Deleteacct extends Controller function handle($argv) { $mod = new DeleteacctModel(); - $this->action_default($mod); + + switch ($_REQUEST['input']['action']) + { + case "delete": + $this->action_delete($mod); + break; + + default: + $this->action_default($mod); + break; + } } function action_default($mod) @@ -23,6 +33,12 @@ class Deleteacct extends Controller $mod->deflt(); include "view/deleteacct/default.view.php"; } + + function action_delete($mod) + { + $mod->del($_REQUEST['input']); + $this->action_default($mod); + } } ?> diff --git a/app/model/deleteacct.mod.php b/app/model/deleteacct.mod.php index ca01a0d..89aca14 100644 --- a/app/model/deleteacct.mod.php +++ b/app/model/deleteacct.mod.php @@ -1,6 +1,8 @@ field_text("password", null, false); + + if (!$form->populate($input)) + { + $this->logFormErrors($form); + return; + } + + $user = $this->getCurrentUser(); + + if (!$user->validatePassword($form->password)) + { + $this->logError("Account not deleted - Password was incorrect"); + return; + } + + if ($user->admin && $user->getNumAdmins() == 1) + { + $this->logError("Account not deleted - Cannot remove the last admin account"); + return; + } + + $user->delObj(); + $this->redirectTo($this->ar() . "/"); + } } ?> -- cgit v1.2.3 From 04cf93366774e7c1a9070013af866380c5f5ad95 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 22 May 2016 16:27:55 -0400 Subject: Add delete account button to all users panels Added button for admins to remove any user account --- app/view/common/setting.modal.view.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/view/common/setting.modal.view.php b/app/view/common/setting.modal.view.php index 845f4ed..60b0ba5 100644 --- a/app/view/common/setting.modal.view.php +++ b/app/view/common/setting.modal.view.php @@ -293,6 +293,17 @@ + +

 

+

 

+ +
+ + + +
-- cgit v1.2.3 From 2d1e4242a87b54578e24546dabe1525a014da24e Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 22 May 2016 16:34:39 -0400 Subject: Add form submission handler for user removal Added handler for the button added in the previous commit. --- app/model/common.mod.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/app/model/common.mod.php b/app/model/common.mod.php index 03ed54f..5e6373c 100644 --- a/app/model/common.mod.php +++ b/app/model/common.mod.php @@ -58,6 +58,7 @@ class CommonModel extends MasterModel case "common-setting-admin": $this->saveSettingAdmin($input); break; case "common-setting-allusers-adduser": $this->saveSettingAllusersAdduser($input); break; case "common-setting-allusers-edituser": $this->saveSettingAllusersEdituser($input, $attachment); break; + case "common-setting-allusers-deluser": $this->saveSettingAllusersDeluser($input); break; } } @@ -283,6 +284,51 @@ class CommonModel extends MasterModel else $this->logFormErrors($form); } + + /* + * Allow admin to remove user accounts + */ + function saveSettingAllusersDeluser($input) + { + $form = new Form(); + $form->field_text("guid"); + + if (!$form->populate($input)) + { + $this->logFormErrors($form); + return; + } + + $user = $this->getCurrentUser(); + + if (!$user || $user->admin == 0) + { + $this->logError("Admin permissions required"); + return; + } + + $user = new User($form->guid); + + if ($user->type != "user") + { + $this->logError("Invalid user GUID"); + return; + } + + if ($user->admin && $user->getNumAdmins() == 1) + { + $this->logError("Account not deleted - Cannot remove the last admin account"); + return; + } + + $user->delObj(); + + if (!$this->getCurrentUser()) + { + /* did user delete their own account? */ + $this->redirectTo($this->ar() . "/"); + } + } } ?> -- cgit v1.2.3