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