From b8b155a613dde6caaa69ed03a9017370489e6d37 Mon Sep 17 00:00:00 2001 From: raisfeld-ori Date: Thu, 21 Mar 2024 15:03:03 +0200 Subject: [PATCH] added the user password/name to the backend --- src-tauri/src/data/json.rs | 4 ++-- src/pages/login/loading.tsx | 6 +++++- src/pages/login/signup.tsx | 5 ----- src/pages/main_page/main_page.tsx | 3 ++- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/data/json.rs b/src-tauri/src/data/json.rs index 56b084f..6b5ada4 100644 --- a/src-tauri/src/data/json.rs +++ b/src-tauri/src/data/json.rs @@ -40,7 +40,7 @@ pub fn user_get<'a>(key: String) -> &'a Value { } #[tauri::command] pub fn system_get<'a>(key: String) -> &'a Value { - return unsafe { + return unsafe { USER_DATA .get("system") .expect("USER_DATA was not initialized") @@ -65,7 +65,7 @@ pub fn create_value(valType: String, val: String) -> Value { pub fn user_make(key: String, data: Value) {user_mut().insert(key, data);} #[tauri::command] -pub fn system_make(key: String, val: Value) {user_mut().insert(key, val);} +pub fn system_make(key: String, val: Value) {system_mut().insert(key, val);} #[derive(Serialize)] struct SerializeUserData{ diff --git a/src/pages/login/loading.tsx b/src/pages/login/loading.tsx index c4fd073..b10f0d7 100644 --- a/src/pages/login/loading.tsx +++ b/src/pages/login/loading.tsx @@ -15,8 +15,12 @@ function loading(){ const [error, set_error] = useState(""); if (!location.state){return

DONT ACCESS THIS PAGE WITHOUT LOGGING IN

} useEffect(() => { - invoke("load_user", location.state).then(result => { + invoke("load_user", location.state).then(async result => { if (result) {set_state("ERROR");set_error("failed to load the user data");return;} + let name_val = await invoke('create_value', {valType: 'string', val: location.state.name}); + await invoke('system_make', {key: 'name',val: name_val}); + let password_val = await invoke('create_value', {valType: 'string', val: location.state.password}); + await invoke('system_make', {key: 'password',val: password_val}); navigate('/main_page'); }); }, []); diff --git a/src/pages/login/signup.tsx b/src/pages/login/signup.tsx index c8c374f..32ecfaa 100644 --- a/src/pages/login/signup.tsx +++ b/src/pages/login/signup.tsx @@ -14,14 +14,9 @@ function Login() { async function authenticate() { let user_exists = await invoke("user_exists", {name, password}); if (!user_exists) { - let name_val = await invoke('create_value', {valType: 'string', val: name}); - await invoke('system_make', {key: 'name',val: name_val}); - let password_val = await invoke('create_value', {valType: 'string', val: password}); - await invoke('system_make', {key: 'password',val: password_val}); await invoke("create_user", {name, password}) await invoke("save_user", {username: name, password}); navigate("/loading", {state: {name, password}}); - } } diff --git a/src/pages/main_page/main_page.tsx b/src/pages/main_page/main_page.tsx index 0751230..4e1d0c1 100644 --- a/src/pages/main_page/main_page.tsx +++ b/src/pages/main_page/main_page.tsx @@ -12,6 +12,7 @@ import leaveicon from './assets/leave.png'; import { useNavigate } from 'react-router-dom'; import exit from './assets/exit.png'; import daddy from './assets/daddyishome.png'; +import { invoke } from '@tauri-apps/api'; @@ -19,7 +20,7 @@ export default function MainPage() { const navigate = useNavigate(); const [app, fs_display] = file_system(); const example_app = desktop_app("Files", folder, () => {fs_display('inherit')}); - const not_example_app = desktop_app("Search", search, () => { console.log("test"); }); + const not_example_app = desktop_app("Search", search, async () => { console.log(await invoke('system_get', {key: 'name'})); }); const terminal = desktop_app("Terminal", terminald, () => {}); const [menu, set_menu] = useState(false); return (