diff --git a/src/cleanup_thread.rs b/src/cleanup_thread.rs index d311666..8b66f3e 100644 --- a/src/cleanup_thread.rs +++ b/src/cleanup_thread.rs @@ -58,6 +58,9 @@ fn do_clean() -> Res { // Clean old conversation messages conversations_helper::clean_old_messages(&user)?; + + // Remove the account, if it have been inactive for a long time + account_helper::remove_if_inactive_for_too_long_time(&user)?; } diff --git a/src/data/user.rs b/src/data/user.rs index f9455f9..96e0c79 100644 --- a/src/data/user.rs +++ b/src/data/user.rs @@ -104,6 +104,7 @@ pub struct User { pub password: String, pub first_name: String, pub last_name: String, + pub last_activity: u64, pub status: UserPageStatus, pub virtual_directory: Option, pub account_image_path: Option, diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index 20f06c1..00614b0 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -356,6 +356,19 @@ pub fn delete(user_id: &UserID) -> ResultBoxError { Ok(()) } +/// Automatically delete the account, if it have been inactive for a too long time +pub fn remove_if_inactive_for_too_long_time(user: &User) -> Res { + if user.delete_account_after < 1 { + return Ok(()); + } + + if user.last_activity < time() - user.delete_account_after { + delete(&user.id)?; + } + + Ok(()) +} + /// Hash the password to store it inside the database fn hash_password(pass: &str) -> Res { Ok(hash_with_result(pass, DEFAULT_COST)?.to_string()) diff --git a/src/helpers/user_helper.rs b/src/helpers/user_helper.rs index 293fe38..cbb3d3b 100644 --- a/src/helpers/user_helper.rs +++ b/src/helpers/user_helper.rs @@ -63,6 +63,7 @@ fn db_to_user(res: &database::RowResult) -> ResultBoxError { first_name: res.get_str("prenom")?, last_name: res.get_str("nom")?, status: page_status, + last_activity: res.get_u64("last_activity")?, virtual_directory: res.get_optional_str("sous_repertoire")?, account_image_path: res.get_optional_str("account_image_path")?, account_image_visibility,