Work progress on account deletion

This commit is contained in:
Pierre 2018-05-09 14:53:08 +02:00
parent 3841d85c64
commit 400d9ab07d
2 changed files with 61 additions and 0 deletions

View File

@ -110,4 +110,24 @@ class accountController {
"success" => "The account has been created !" "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!");
}
} }

View File

@ -252,6 +252,47 @@ class AccountComponent {
public function cryptPassword(string $userPassword) : string { public function cryptPassword(string $userPassword) : string {
return crypt(sha1($userPassword), sha1($userPassword)); 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 //Register class