Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
added the user password/name to the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
raisfeld-ori committed Mar 21, 2024
1 parent 248cdac commit b8b155a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/data/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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{
Expand Down
6 changes: 5 additions & 1 deletion src/pages/login/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ function loading(){
const [error, set_error] = useState("");
if (!location.state){return <h1>DONT ACCESS THIS PAGE WITHOUT LOGGING IN</h1>}
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');
});
}, []);
Expand Down
5 changes: 0 additions & 5 deletions src/pages/login/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}});

}
}

Expand Down
3 changes: 2 additions & 1 deletion src/pages/main_page/main_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ 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';



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 (
Expand Down

0 comments on commit b8b155a

Please sign in to comment.