Krimskrams
This commit is contained in:
parent
c6ea22b445
commit
e1bf152fdd
3 changed files with 30 additions and 4 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::auth::auth_connector::unregister_user;
|
||||
use crate::communities::community::Community;
|
||||
use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes};
|
||||
use crate::gui::log_panel::log_message;
|
||||
|
|
@ -78,6 +79,11 @@ pub async fn handle(
|
|||
} else {
|
||||
let uuid = Uuid::parse_str(body.unwrap()["uuid"].as_str().unwrap())
|
||||
.unwrap();
|
||||
unregister_user(
|
||||
uuid,
|
||||
&user_manager::get_user(uuid).unwrap().reset_token,
|
||||
)
|
||||
.await;
|
||||
user_manager::remove_user(uuid);
|
||||
"{}".to_string()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use crate::auth::auth_connector;
|
||||
use crate::gui::log_panel::log_message;
|
||||
use crate::users::user_manager;
|
||||
use crate::util::file_util::{has_file, load_file, used_dir_space};
|
||||
use base64::{Engine as _, engine::general_purpose};
|
||||
use json::{JsonValue, object};
|
||||
use rand::Rng;
|
||||
|
|
@ -15,6 +18,7 @@ pub struct UserProfile {
|
|||
pub public_key: String,
|
||||
pub private_key_hash: String,
|
||||
pub reset_token: String,
|
||||
pub created_at: i64,
|
||||
pub display_name: Option<String>,
|
||||
}
|
||||
|
||||
|
|
@ -33,6 +37,10 @@ impl UserProfile {
|
|||
display_name,
|
||||
public_key,
|
||||
private_key_hash,
|
||||
created_at: SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_millis() as i64,
|
||||
reset_token,
|
||||
}
|
||||
}
|
||||
|
|
@ -43,6 +51,7 @@ impl UserProfile {
|
|||
"username" => self.username.clone(),
|
||||
"public_key" => self.public_key.clone(),
|
||||
"private_key_hash" => self.private_key_hash.clone(),
|
||||
"created_at" => self.created_at,
|
||||
"reset_token" => self.reset_token.clone()
|
||||
};
|
||||
if let Some(d) = &self.display_name {
|
||||
|
|
@ -56,28 +65,36 @@ impl UserProfile {
|
|||
"username" => self.username.clone(),
|
||||
"public_key" => self.public_key.clone(),
|
||||
"private_key_hash" => self.private_key_hash.clone(),
|
||||
"created_at" => self.created_at,
|
||||
"storage" => used_dir_space(&format!("users/{}", self.user_id.to_string())),
|
||||
};
|
||||
if let Some(d) = &self.display_name {
|
||||
obj["display_name"] = d.clone().into();
|
||||
}
|
||||
if has_file("", &format!("{}.tu", self.username.clone())) {
|
||||
obj["tu"] = load_file("", &format!("{}.tu", self.username.clone())).into();
|
||||
}
|
||||
|
||||
obj
|
||||
}
|
||||
pub async fn from_json(j: &JsonValue) -> Option<Self> {
|
||||
let uuid = Uuid::parse_str(j["uuid"].as_str()?).ok()?;
|
||||
let user_id = Uuid::parse_str(j["uuid"].as_str()?).ok()?;
|
||||
let username = j["username"].as_str()?.to_string();
|
||||
let public_key = j["public_key"].as_str()?.to_string();
|
||||
let private_key_hash = j["private_key_hash"].as_str()?.to_string();
|
||||
let reset_token = j["reset_token"].as_str()?.to_string();
|
||||
let created_at = j["created_at"].as_i64()?;
|
||||
let display_name = j["display_name"].as_str().map(|s| s.to_string());
|
||||
|
||||
let mut up = UserProfile::new(
|
||||
uuid,
|
||||
let mut up = UserProfile {
|
||||
user_id,
|
||||
username,
|
||||
display_name,
|
||||
public_key,
|
||||
private_key_hash,
|
||||
created_at,
|
||||
reset_token,
|
||||
);
|
||||
};
|
||||
|
||||
if j.has_key("migrate")
|
||||
|| j.has_key("migrating")
|
||||
|
|
|
|||
|
|
@ -190,6 +190,9 @@ pub fn get_directory() -> String {
|
|||
pub fn used_space() -> u64 {
|
||||
get_directory_size(&PathBuf::from(get_directory()))
|
||||
}
|
||||
pub fn used_dir_space(path: &str) -> u64 {
|
||||
get_directory_size(&PathBuf::from(format!("{}/{}", get_directory(), path)))
|
||||
}
|
||||
|
||||
pub fn get_directory_size(directory: &Path) -> u64 {
|
||||
let mut size = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue