API mods
This commit is contained in:
parent
f88888983e
commit
24431f2167
6 changed files with 42 additions and 13 deletions
|
|
@ -142,7 +142,7 @@ pub async fn migrate_user(user_profile: &mut UserProfile) -> bool {
|
||||||
let client = client();
|
let client = client();
|
||||||
|
|
||||||
let mut payload = JsonValue::new_object();
|
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["reset_token"] = user_profile.reset_token.clone().into();
|
||||||
payload["new_token"] = user_profile.randomize_reset_token().into();
|
payload["new_token"] = user_profile.randomize_reset_token().into();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,8 @@ pub enum DataTypes {
|
||||||
challenge,
|
challenge,
|
||||||
community_title,
|
community_title,
|
||||||
communities,
|
communities,
|
||||||
|
|
||||||
|
user,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DataTypes {
|
impl DataTypes {
|
||||||
|
|
@ -153,6 +155,8 @@ impl DataTypes {
|
||||||
"challenge" => DataTypes::challenge,
|
"challenge" => DataTypes::challenge,
|
||||||
"communitytitle" => DataTypes::community_title,
|
"communitytitle" => DataTypes::community_title,
|
||||||
"communities" => DataTypes::communities,
|
"communities" => DataTypes::communities,
|
||||||
|
|
||||||
|
"user" => DataTypes::user,
|
||||||
_ => DataTypes::error_type, // fallback if unknown
|
_ => DataTypes::error_type, // fallback if unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -215,6 +219,8 @@ pub enum CommunicationType {
|
||||||
end_call,
|
end_call,
|
||||||
function,
|
function,
|
||||||
update,
|
update,
|
||||||
|
|
||||||
|
create_user,
|
||||||
}
|
}
|
||||||
impl CommunicationType {
|
impl CommunicationType {
|
||||||
pub fn parse(p0: String) -> CommunicationType {
|
pub fn parse(p0: String) -> CommunicationType {
|
||||||
|
|
@ -269,6 +275,8 @@ impl CommunicationType {
|
||||||
"endcall" => CommunicationType::end_call,
|
"endcall" => CommunicationType::end_call,
|
||||||
"function" => CommunicationType::function,
|
"function" => CommunicationType::function,
|
||||||
"update" => CommunicationType::update,
|
"update" => CommunicationType::update,
|
||||||
|
|
||||||
|
"createuser" => CommunicationType::create_user,
|
||||||
_ => CommunicationType::error,
|
_ => CommunicationType::error,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
src/main.rs
14
src/main.rs
|
|
@ -58,10 +58,10 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BASIC CONFIGURATION
|
// BASIC CONFIGURATION
|
||||||
CONFIG.lock().unwrap().load();
|
CONFIG.lock().await.load();
|
||||||
if !CONFIG.lock().unwrap().config.has_key("iota_id") {
|
if !CONFIG.lock().await.config.has_key("iota_id") {
|
||||||
CONFIG.lock().unwrap().change("iota_id", Uuid::new_v4());
|
CONFIG.lock().await.change("iota_id", Uuid::new_v4());
|
||||||
CONFIG.lock().unwrap().update();
|
CONFIG.lock().await.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// USER MANAGEMENT
|
// USER MANAGEMENT
|
||||||
|
|
@ -84,7 +84,7 @@ async fn main() {
|
||||||
"IOTA ID: {}-####-####-####-############",
|
"IOTA ID: {}-####-####-####-############",
|
||||||
CONFIG
|
CONFIG
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.await
|
||||||
.get_iota_id()
|
.get_iota_id()
|
||||||
.to_string()
|
.to_string()
|
||||||
.split("-")
|
.split("-")
|
||||||
|
|
@ -107,7 +107,7 @@ async fn main() {
|
||||||
sb1 = sb1 + ",";
|
sb1 = sb1 + ",";
|
||||||
}
|
}
|
||||||
log_message(format!("Community IDS: {}", 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 {
|
if start(port).await {
|
||||||
log_message(format("community_active", &[&port.to_string()]));
|
log_message(format("community_active", &[&port.to_string()]));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -133,7 +133,7 @@ async fn main() {
|
||||||
.add_data(DataTypes::user_ids, String(sb.to_string()))
|
.add_data(DataTypes::user_ids, String(sb.to_string()))
|
||||||
.add_data(
|
.add_data(
|
||||||
DataTypes::iota_id,
|
DataTypes::iota_id,
|
||||||
String(CONFIG.lock().unwrap().get_iota_id().to_string()),
|
String(CONFIG.lock().await.get_iota_id().to_string()),
|
||||||
)
|
)
|
||||||
.to_json()
|
.to_json()
|
||||||
.to_string()
|
.to_string()
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
|
use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes};
|
||||||
use crate::gui::log_panel::log_message;
|
use crate::gui::log_panel::log_message;
|
||||||
use axum::http::HeaderValue;
|
use axum::http::HeaderValue;
|
||||||
use http_body_util::Full;
|
use http_body_util::Full;
|
||||||
use hyper::body::Bytes;
|
use hyper::body::Bytes;
|
||||||
use hyper::{HeaderMap, Response as HttpResponse, StatusCode};
|
use hyper::{HeaderMap, Response as HttpResponse, StatusCode};
|
||||||
use json::JsonValue;
|
use json::JsonValue;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::util::config_util::CONFIG;
|
use crate::util::config_util::CONFIG;
|
||||||
use crate::{APP_STATE, communities::community_manager, users::user_manager};
|
use crate::{APP_STATE, communities::community_manager, users::user_manager};
|
||||||
|
|
@ -31,8 +33,27 @@ pub async fn handle(
|
||||||
"users" => (StatusCode::OK, "application/json", {
|
"users" => (StatusCode::OK, "application/json", {
|
||||||
if path_parts.len() >= 4 {
|
if path_parts.len() >= 4 {
|
||||||
match path_parts[3] {
|
match path_parts[3] {
|
||||||
"add" => "{}".to_string(),
|
"add" => {
|
||||||
"remove" => "{}".to_string(),
|
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" => {
|
"get" => {
|
||||||
let users = user_manager::get_users();
|
let users = user_manager::get_users();
|
||||||
let mut json = JsonValue::new_array();
|
let mut json = JsonValue::new_array();
|
||||||
|
|
@ -61,7 +82,7 @@ pub async fn handle(
|
||||||
json.to_string()
|
json.to_string()
|
||||||
}),
|
}),
|
||||||
"settings" => (StatusCode::OK, "application/json", {
|
"settings" => (StatusCode::OK, "application/json", {
|
||||||
CONFIG.lock().unwrap().config.to_string()
|
CONFIG.lock().await.config.to_string()
|
||||||
}),
|
}),
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
||||||
reset_token,
|
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(
|
save_file(
|
||||||
"",
|
"",
|
||||||
&format!("{}.tu", username),
|
&format!("{}.tu", username),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::util::file_util::{load_file, save_file};
|
use crate::util::file_util::{load_file, save_file};
|
||||||
use json::JsonValue;
|
use json::JsonValue;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub static CONFIG: Lazy<Mutex<ConfigUtil>> = Lazy::new(|| Mutex::new(ConfigUtil::new()));
|
pub static CONFIG: Lazy<Mutex<ConfigUtil>> = Lazy::new(|| Mutex::new(ConfigUtil::new()));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue