mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Add server database interaction
This commit is contained in:
@@ -18,7 +18,3 @@ backend = "http://localhost:3000/api" # Address to proxy requests to
|
||||
# no_system_proxy = false # Disable system proxy
|
||||
# rewrite = "" # Strip the given prefix off paths
|
||||
# no_redirect = false # Disable following redirects of proxy responses
|
||||
|
||||
|
||||
[[proxy]]
|
||||
backend = "http://localhost:3000/auth"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use egui::{Align2, Area, Color32, Frame, Order, Sense, UiKind, Vec2, mutex::Mutex};
|
||||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
use serde_json::json;
|
||||
use std::sync::Arc;
|
||||
use std::{marker::PhantomData, sync::Arc};
|
||||
use wasm_bindgen::prelude::Closure;
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
@@ -114,7 +115,7 @@ impl Auth {
|
||||
let state = self.auth_state.clone();
|
||||
|
||||
crate::httpPost(
|
||||
"/auth",
|
||||
"/api/auth",
|
||||
&json!({
|
||||
"username": self.username.clone(),
|
||||
"password": self.password.clone()
|
||||
@@ -149,15 +150,24 @@ impl Auth {
|
||||
// });
|
||||
}
|
||||
|
||||
pub fn test(&self) {
|
||||
pub fn get<T, F>(&self, path: &str, ret: F)
|
||||
where
|
||||
F: FnOnce(Result<T, String>) + 'static,
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
if let Some(ref token) = self.token {
|
||||
let state = self.auth_state.clone();
|
||||
crate::httpGetAuth(
|
||||
"/api/test1234/kjhejwer/kwherjwer/iuwehrhiwer/wiuerhjwer",
|
||||
path,
|
||||
format!("Bearer {}", token.token),
|
||||
Closure::once_into_js(move |ok: bool, response: String| {
|
||||
if ok {
|
||||
crate::log(&response);
|
||||
if let Ok(value) = serde_json::from_str::<Result<T, String>>(&response) {
|
||||
ret(value)
|
||||
} else {
|
||||
*(state.lock()) = AuthState::Error("Malformed Response".into());
|
||||
}
|
||||
} else {
|
||||
*(state.lock()) = AuthState::Error(response);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,34 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use egui::Color32;
|
||||
|
||||
use crate::auth::Auth;
|
||||
|
||||
#[derive(Default, serde::Deserialize, serde::Serialize)]
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
pub struct Config {
|
||||
response_text: String,
|
||||
response_text: Arc<Mutex<String>>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
response_text: Arc::new(Mutex::new("NONE".to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn update(&mut self, auth: &mut Auth, ui: &mut egui::Ui) {
|
||||
if ui.button("Test").clicked() {
|
||||
auth.test();
|
||||
if ui.button("Set Value").clicked() {
|
||||
let text_clone = self.response_text.clone();
|
||||
auth.get("/api/test", move |response: Result<String, String>| {
|
||||
*text_clone.lock().unwrap() = format!("{:?}", response);
|
||||
});
|
||||
}
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Response: ");
|
||||
ui.colored_label(Color32::WHITE, &*self.response_text.lock().unwrap());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user