From 400d9ab07d5b8050b580f4274c549e544619c819 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 9 May 2018 14:53:08 +0200 Subject: [PATCH] Work progress on account deletion --- RestControllers/accountController.php | 20 ++++++++++++ classes/components/AccountComponent.php | 41 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/RestControllers/accountController.php b/RestControllers/accountController.php index 2447d37..17a10e2 100644 --- a/RestControllers/accountController.php +++ b/RestControllers/accountController.php @@ -110,4 +110,24 @@ class accountController { "success" => "The account has been created !" ); } + + /** + * Delete an account + * + * @url POST /account/delete + */ + public function deleteAccount(){ + + //Login & valid password required + user_login_required(); + check_post_password(userID, "password"); + + //Try to delet the account + if(!components()->account->delete(userID)) + Rest_fatal_error(500, "An error occurred while trying to delete your account!"); + + //Success + return array("success" => "The user account has been successfully deleted!"); + + } } \ No newline at end of file diff --git a/classes/components/AccountComponent.php b/classes/components/AccountComponent.php index b53f85e..891f5a9 100644 --- a/classes/components/AccountComponent.php +++ b/classes/components/AccountComponent.php @@ -252,6 +252,47 @@ class AccountComponent { public function cryptPassword(string $userPassword) : string { return crypt(sha1($userPassword), sha1($userPassword)); } + + /** + * Delete user account + * + * @param int $userID The ID of the account to delete + * @return bool TRUE for a success / FALSE else + */ + public function delete(int $userID) : bool { + + //Delete user comments + if(!components()->comments->deleteAllUser($userID)) + return false; + + //Delete user posts + if(!components()->posts->deleteAllUser($userID)) + return false; + + //Delete user participation in surveys + if(!components()->survey->cancel_all_user_responses($userID)) + return false; + + //Delete all the likes created by the user + if(!components()->likes->delete_all_user($userID)) + return false; + + //Delete user movies + + //Delete conversation messages + + //Remove users from all its conversations + + //Delete all the notifications related with the user + + //Delete all user friends, including friendship requests + + //Delete user account image + + //Delete connections to all the services + + //Delete user from the database + } } //Register class