From f031f7b4b3262f2c21bcc4b2d63ce75269317bbe Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 20 Jan 2021 18:58:02 +0100 Subject: [PATCH] Ready to start to delete user account --- src/controllers/account_controller.rs | 12 +++++++++--- src/helpers/account_helper.rs | 11 +++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/controllers/account_controller.rs b/src/controllers/account_controller.rs index 2279d5f..ca0c158 100644 --- a/src/controllers/account_controller.rs +++ b/src/controllers/account_controller.rs @@ -9,7 +9,7 @@ use crate::api_data::res_check_security_questions_exists::ResCheckSecurityQuesti use crate::api_data::res_get_security_questions::ResGetSecurityQuestions; use crate::constants::PASSWORD_RESET_TOKEN_LENGTH; use crate::controllers::routes::RequestResult; -use crate::data::error::{ExecError, ResultBoxError}; +use crate::data::error::ResultBoxError; use crate::data::http_request_handler::HttpRequestHandler; use crate::data::new_account::NewAccount; use crate::data::user::{User, UserID}; @@ -194,6 +194,12 @@ pub fn export_data(r: &mut HttpRequestHandler) -> RequestResult { pub fn delete_account(r: &mut HttpRequestHandler) -> RequestResult { r.need_user_password("password")?; - // TODO : implement me - r.internal_error(ExecError::boxed_new("Not implemented yet")) + if r.user_id()?.id() < 2 { + // I do not want anybody delete my account... + r.forbidden("You shall not delete MY account (whoever you are, please note that hacking is bad !!!)".to_string())?; + } + + account_helper::delete(r.user_id_ref()?); + + r.success("Account deleted.") } \ No newline at end of file diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index d029184..17f0d4e 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -297,4 +297,15 @@ pub fn export(user_id: &UserID) -> ResultBoxError { } Ok(data) +} + +/// Delete a user's account +pub fn delete(user_id: &UserID) -> ResultBoxError { + // TODO : close all websockets of user + + // TODO : Delete all group membership + + // TODO : continue work here + + Ok(()) } \ No newline at end of file