This commit is contained in:
Alex Emmet 2025-11-21 16:37:13 +01:00
commit 24431f2167
6 changed files with 42 additions and 13 deletions

View file

@ -142,7 +142,7 @@ pub async fn migrate_user(user_profile: &mut UserProfile) -> bool {
let client = client();
let mut payload = JsonValue::new_object();
payload["iota_id"] = JsonValue::String(CONFIG.lock().unwrap().get_iota_id().to_string());
payload["iota_id"] = JsonValue::String(CONFIG.lock().await.get_iota_id().to_string());
payload["reset_token"] = user_profile.reset_token.clone().into();
payload["new_token"] = user_profile.randomize_reset_token().into();

View file

@ -77,6 +77,8 @@ pub enum DataTypes {
challenge,
community_title,
communities,
user,
}
impl DataTypes {
@ -153,6 +155,8 @@ impl DataTypes {
"challenge" => DataTypes::challenge,
"communitytitle" => DataTypes::community_title,
"communities" => DataTypes::communities,
"user" => DataTypes::user,
_ => DataTypes::error_type, // fallback if unknown
}
}
@ -215,6 +219,8 @@ pub enum CommunicationType {
end_call,
function,
update,
create_user,
}
impl CommunicationType {
pub fn parse(p0: String) -> CommunicationType {
@ -269,6 +275,8 @@ impl CommunicationType {
"endcall" => CommunicationType::end_call,
"function" => CommunicationType::function,
"update" => CommunicationType::update,
"createuser" => CommunicationType::create_user,
_ => CommunicationType::error,
}
}

View file

@ -58,10 +58,10 @@ async fn main() {
}
// BASIC CONFIGURATION
CONFIG.lock().unwrap().load();
if !CONFIG.lock().unwrap().config.has_key("iota_id") {
CONFIG.lock().unwrap().change("iota_id", Uuid::new_v4());
CONFIG.lock().unwrap().update();
CONFIG.lock().await.load();
if !CONFIG.lock().await.config.has_key("iota_id") {
CONFIG.lock().await.change("iota_id", Uuid::new_v4());
CONFIG.lock().await.update();
}
// USER MANAGEMENT
@ -84,7 +84,7 @@ async fn main() {
"IOTA ID: {}-####-####-####-############",
CONFIG
.lock()
.unwrap()
.await
.get_iota_id()
.to_string()
.split("-")
@ -107,7 +107,7 @@ async fn main() {
sb1 = sb1 + ",";
}
log_message(format!("Community IDS: {}", sb1));
let port = CONFIG.lock().unwrap().get_port();
let port = CONFIG.lock().await.get_port();
if start(port).await {
log_message(format("community_active", &[&port.to_string()]));
} else {
@ -133,7 +133,7 @@ async fn main() {
.add_data(DataTypes::user_ids, String(sb.to_string()))
.add_data(
DataTypes::iota_id,
String(CONFIG.lock().unwrap().get_iota_id().to_string()),
String(CONFIG.lock().await.get_iota_id().to_string()),
)
.to_json()
.to_string()

View file

@ -1,9 +1,11 @@
use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes};
use crate::gui::log_panel::log_message;
use axum::http::HeaderValue;
use http_body_util::Full;
use hyper::body::Bytes;
use hyper::{HeaderMap, Response as HttpResponse, StatusCode};
use json::JsonValue;
use uuid::Uuid;
use crate::util::config_util::CONFIG;
use crate::{APP_STATE, communities::community_manager, users::user_manager};
@ -31,8 +33,27 @@ pub async fn handle(
"users" => (StatusCode::OK, "application/json", {
if path_parts.len() >= 4 {
match path_parts[3] {
"add" => "{}".to_string(),
"remove" => "{}".to_string(),
"add" => {
let username = headers.get("username");
if let (Some(user), Some(_private_key)) = user_manager::create_user(
&username.unwrap().to_str().unwrap().to_string(),
)
.await
{
let cv = CommunicationValue::new(CommunicationType::create_user)
.add_data(DataTypes::user, user.to_json());
cv.to_json().to_string()
} else {
"{}".to_string()
}
}
"remove" => {
let uuid =
Uuid::parse_str(headers.get("uuid").unwrap().to_str().unwrap())
.unwrap();
user_manager::remove_user(uuid);
"{}".to_string()
}
"get" => {
let users = user_manager::get_users();
let mut json = JsonValue::new_array();
@ -61,7 +82,7 @@ pub async fn handle(
json.to_string()
}),
"settings" => (StatusCode::OK, "application/json", {
CONFIG.lock().unwrap().config.to_string()
CONFIG.lock().await.config.to_string()
}),
_ => {

View file

@ -44,7 +44,7 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
reset_token,
);
auth_connector::complete_register(&up, &CONFIG.lock().unwrap().get_iota_id().to_string()).await;
auth_connector::complete_register(&up, &CONFIG.lock().await.get_iota_id().to_string()).await;
save_file(
"",
&format!("{}.tu", username),

View file

@ -1,7 +1,7 @@
use crate::util::file_util::{load_file, save_file};
use json::JsonValue;
use once_cell::sync::Lazy;
use std::sync::Mutex;
use tokio::sync::Mutex;
use uuid::Uuid;
pub static CONFIG: Lazy<Mutex<ConfigUtil>> = Lazy::new(|| Mutex::new(ConfigUtil::new()));