1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Can change user account image

This commit is contained in:
2021-01-19 18:27:56 +01:00
parent 364a98634f
commit e02c0ba2b9
3 changed files with 48 additions and 0 deletions

View File

@ -13,6 +13,7 @@ use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo};
use crate::utils::crypt_utils::{crypt_pass, rand_str};
use crate::utils::date_utils::{mysql_date, time};
use crate::data::security_settings::SecuritySettings;
use crate::utils::user_data_utils::user_data_path;
/// Account helper
///
@ -232,6 +233,39 @@ pub fn set_security_settings(settings: &SecuritySettings) -> ResultBoxError {
.exec()
}
/// Delete user account image
pub fn delete_account_image(user_id: &UserID) -> ResultBoxError {
let user = user_helper::find_user_by_id(user_id)?;
if !user.has_account_image() {
return Ok(());
}
let path = user_data_path(user.account_image_path.unwrap().as_ref());
if path.exists()
{
std::fs::remove_file(path)?;
}
database::UpdateInfo::new(USERS_TABLE)
.cond_user_id("ID", user_id)
.set_str("account_image_path", "")
.exec()
}
/// Set a new account image
pub fn set_account_image(user_id: &UserID, uri: &String) -> ResultBoxError {
// First, delete the previous account image
delete_account_image(user_id)?;
// Update database
database::UpdateInfo::new(USERS_TABLE)
.cond_user_id("ID", user_id)
.set_str("account_image_path", uri)
.exec()
}
/// Export an account's data
pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
let mut data = AccountExport {