mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Automatically delete old account after a period of inactivity
This commit is contained in:
parent
f44e5103ca
commit
fa230bdef8
@ -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)?;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<String>,
|
||||
pub account_image_path: Option<String>,
|
||||
|
@ -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<String> {
|
||||
Ok(hash_with_result(pass, DEFAULT_COST)?.to_string())
|
||||
|
@ -63,6 +63,7 @@ fn db_to_user(res: &database::RowResult) -> ResultBoxError<User> {
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user