iota auth
This commit is contained in:
parent
0d51dc9ac7
commit
9ec90f0e19
3 changed files with 36 additions and 26 deletions
|
|
@ -1,12 +1,9 @@
|
|||
use json::JsonValue;
|
||||
use json::number::Number;
|
||||
use json::{self};
|
||||
use once_cell::sync::Lazy;
|
||||
use pnet::datalink::NetworkInterface;
|
||||
use std::sync::Arc;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::Mutex;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::time::{Duration, sleep};
|
||||
|
||||
|
|
@ -31,8 +28,7 @@ use crate::gui::log_panel::{log_message, log_message_trans};
|
|||
use crate::gui::tui;
|
||||
use crate::langu::language_creator;
|
||||
use crate::langu::language_manager::format;
|
||||
use crate::omikron::omikron_connection::OMIKRON_CONNECTION;
|
||||
use crate::omikron::omikron_connection::OmikronConnection;
|
||||
use crate::omikron::omikron_connection::{OMIKRON_CONNECTION, OmikronConnection};
|
||||
use crate::server::server::start;
|
||||
use crate::users::user_manager;
|
||||
use crate::util::config_util::CONFIG;
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
use crate::auth::local_auth;
|
||||
use crate::gui::log_panel::{log_cv, log_message_format};
|
||||
use crate::{
|
||||
data::communication::{CommunicationType, CommunicationValue, DataTypes},
|
||||
gui::log_panel::{log_message, log_message_trans},
|
||||
util::{config_util::CONFIG, crypto_helper},
|
||||
};
|
||||
use json::JsonValue;
|
||||
|
||||
use crate::users::contact::Contact;
|
||||
use crate::users::user_community_util::UserCommunityUtil;
|
||||
use crate::util::chats_util::{get_user, mod_user};
|
||||
use crate::util::file_util::{get_children, load_file, save_file};
|
||||
use crate::util::{chat_files, chats_util};
|
||||
use crate::{ACTIVE_TASKS, SHUTDOWN};
|
||||
use crate::{
|
||||
data::communication::{CommunicationType, CommunicationValue, DataTypes},
|
||||
gui::log_panel::{log_message, log_message_trans},
|
||||
util::{config_util::CONFIG, crypto_helper},
|
||||
};
|
||||
use dashmap::DashMap;
|
||||
use futures::Stream;
|
||||
use futures::stream::{SplitSink, SplitStream};
|
||||
|
|
@ -20,6 +18,7 @@ use futures_util::sink::Sink;
|
|||
use futures_util::{SinkExt, StreamExt};
|
||||
use hyper::upgrade::Upgraded;
|
||||
use hyper_util::rt::TokioIo;
|
||||
use json::JsonValue;
|
||||
use json::number::Number;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
|
|
@ -101,10 +100,10 @@ impl OmikronConnection {
|
|||
let iota_id = conf.get_iota_id();
|
||||
let public_key = conf.get_public_key();
|
||||
let private_key = conf.get_private_key();
|
||||
drop(conf); // release read lock
|
||||
|
||||
if iota_id == 0 || public_key.is_none() || private_key.is_none() {
|
||||
// Registration flow
|
||||
drop(conf); // release read lock
|
||||
log_message_trans("iota_register_new");
|
||||
let key_pair = crypto_helper::generate_keypair();
|
||||
let public_key_base64 = crypto_helper::public_key_to_base64(&key_pair.public);
|
||||
|
|
@ -118,13 +117,31 @@ impl OmikronConnection {
|
|||
|
||||
if self.connect_internal().await {
|
||||
// a new helper function to just connect
|
||||
self.send_message(
|
||||
CommunicationValue::new(CommunicationType::register_iota)
|
||||
.add_data(DataTypes::public_key, JsonValue::String(public_key_base64))
|
||||
.to_json()
|
||||
.to_string(),
|
||||
match self
|
||||
.clone()
|
||||
.await_response(
|
||||
&CommunicationValue::new(CommunicationType::register_iota)
|
||||
.add_data(DataTypes::public_key, JsonValue::String(public_key_base64)),
|
||||
Some(Duration::from_secs(20)),
|
||||
)
|
||||
.await;
|
||||
.await
|
||||
{
|
||||
Ok(response_cv) => {
|
||||
let iota_json = response_cv
|
||||
.get_data(DataTypes::register_id)
|
||||
.unwrap_or(&JsonValue::Null);
|
||||
let iota_id = iota_json.as_i64().unwrap_or(0);
|
||||
|
||||
let mut conf_write = CONFIG.write().await;
|
||||
conf_write.change("iota_id", iota_json.clone());
|
||||
conf_write.update();
|
||||
drop(conf_write);
|
||||
log_message(format!("Registered with Iota-ID: {}", iota_id));
|
||||
}
|
||||
Err(timeout) => {
|
||||
log_message(timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Login flow
|
||||
|
|
@ -157,7 +174,7 @@ impl OmikronConnection {
|
|||
.unwrap_or("wss://app.tensamin.net/ws/iota/");
|
||||
let stream_res = connect_async(addr).await;
|
||||
if let Err(e) = stream_res {
|
||||
log_message(format!("omikron_connection_error {}", e.to_string()));
|
||||
log_message(format!("con error {}", e.to_string()));
|
||||
return false;
|
||||
}
|
||||
let (stream, _) = stream_res.unwrap();
|
||||
|
|
@ -298,10 +315,10 @@ impl OmikronConnection {
|
|||
|
||||
return;
|
||||
}
|
||||
if cv.is_type(CommunicationType::register_iota_success) {
|
||||
if cv.is_type(CommunicationType::success) {
|
||||
let iota_id = cv
|
||||
.get_data(DataTypes::iota_id)
|
||||
.unwrap()
|
||||
.unwrap_or(&JsonValue::Null)
|
||||
.as_i64()
|
||||
.unwrap_or(0);
|
||||
if iota_id != 0 {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ use crate::data::communication::{CommunicationType, CommunicationValue, DataType
|
|||
use crate::gui::log_panel::log_message;
|
||||
use crate::omikron::omikron_connection::{OMIKRON_CONNECTION, OmikronConnection};
|
||||
use crate::users::user_profile::UserProfile;
|
||||
use crate::util::config_util::CONFIG;
|
||||
use crate::util::crypto_helper::{self, public_key_to_base64};
|
||||
use crate::util::file_util::{load_file, save_file};
|
||||
use crate::{RELOAD, SHUTDOWN};
|
||||
|
|
@ -112,8 +111,6 @@ pub async fn create_user(username: &str) -> (Option<UserProfile>, Option<String>
|
|||
} else {
|
||||
return (None, None);
|
||||
}
|
||||
// auth_connector::complete_register(&up, &CONFIG.read().await.get_iota_id().to_string()).await;
|
||||
//
|
||||
*SHUTDOWN.write().await = true;
|
||||
*RELOAD.write().await = true;
|
||||
log_message("Created User");
|
||||
|
|
|
|||
Loading…
Reference in a new issue