diff --git a/.gitignore b/.gitignore index 996c3e4..645e7bf 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ frontend/node_modules/ # Added by cargo /target +.antigravitycli/ diff --git a/backend/src/handlers/auth.rs b/backend/src/handlers/auth.rs index b58c717..282ee96 100644 --- a/backend/src/handlers/auth.rs +++ b/backend/src/handlers/auth.rs @@ -418,28 +418,39 @@ pub async fn update_user( State(data): State>, Json(body): Json, ) -> Result)> { - let argon = Argon2::default(); - let salt = SaltString::generate(&mut OsRng); - let hashed_pwd = match argon.hash_password(body.new_pwd.clone().as_bytes(), &salt) { - Ok(h) => h.to_string(), - Err(e) => panic!("Error hashing {:}", e), - }; + let update_result = if !body.new_pwd.is_empty() { + let argon = Argon2::default(); + let salt = SaltString::generate(&mut OsRng); + let hashed_pwd = match argon.hash_password(body.new_pwd.clone().as_bytes(), &salt) { + Ok(h) => h.to_string(), + Err(e) => panic!("Error hashing {:}", e), + }; - let update_result = sqlx::query(r#"UPDATE users SET first_name = $1, last_name = $2, username = $3, pwd = $4, is_admin = $5 WHERE id = $6"#) - .bind(body.first_name.to_owned()) - .bind(body.last_name.to_owned()) - .bind(body.username.to_owned()) - .bind(&hashed_pwd) - .bind(body.make_admin.to_owned()) - .bind(id) - .execute(&data.db) - .await - .map_err(|e| { - ( - StatusCode::INTERNAL_SERVER_ERROR, - Json(json!({"status": "error", "message": format!("{:?}", e)})), - ) - })?; + sqlx::query(r#"UPDATE users SET first_name = $1, last_name = $2, username = $3, pwd = $4, is_admin = $5 WHERE id = $6"#) + .bind(body.first_name.to_owned()) + .bind(body.last_name.to_owned()) + .bind(body.username.to_owned()) + .bind(hashed_pwd) + .bind(body.make_admin.to_owned()) + .bind(id) + .execute(&data.db) + .await + } else { + sqlx::query(r#"UPDATE users SET first_name = $1, last_name = $2, username = $3, is_admin = $4 WHERE id = $5"#) + .bind(body.first_name.to_owned()) + .bind(body.last_name.to_owned()) + .bind(body.username.to_owned()) + .bind(body.make_admin.to_owned()) + .bind(id) + .execute(&data.db) + .await + } + .map_err(|e| { + ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"status": "error", "message": format!("{:?}", e)})), + ) + })?; if update_result.rows_affected() == 0 { let error_response = serde_json::json!({ diff --git a/frontend/index.html b/frontend/index.html index ca20c57..3386746 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -4,6 +4,8 @@ + + Yew App diff --git a/frontend/src/assets/csg.png b/frontend/src/assets/csg.png new file mode 100644 index 0000000..6a8e356 Binary files /dev/null and b/frontend/src/assets/csg.png differ diff --git a/frontend/src/assets/favicon.ico b/frontend/src/assets/favicon.ico new file mode 100644 index 0000000..d0b5e36 Binary files /dev/null and b/frontend/src/assets/favicon.ico differ diff --git a/frontend/src/lib.rs b/frontend/src/lib.rs index e8e8222..f1a4bcb 100644 --- a/frontend/src/lib.rs +++ b/frontend/src/lib.rs @@ -269,6 +269,7 @@ fn switch(route: Route) -> Html { pub fn app() -> Html { html! { + render={switch} /> } diff --git a/frontend/src/pages/basic_pages.rs b/frontend/src/pages/basic_pages.rs index b9247f2..064f03c 100644 --- a/frontend/src/pages/basic_pages.rs +++ b/frontend/src/pages/basic_pages.rs @@ -109,3 +109,10 @@ pub fn denied_component() -> Html { } } + +#[component(Icon)] +pub fn icon_component() -> Html { + html! { + + } +} diff --git a/frontend/src/pages/user.rs b/frontend/src/pages/user.rs index fdc3841..0b93d1b 100644 --- a/frontend/src/pages/user.rs +++ b/frontend/src/pages/user.rs @@ -336,7 +336,7 @@ pub fn login_component() -> Html { value={(*username).clone()} oninput={Callback::from(move |e: InputEvent| { let input: web_sys::HtmlInputElement = e.target_unchecked_into(); - username.set(input.value()); + username.set(input.value()); })} /> Html { let last_name = (*last_name).clone(); let username = (*username).clone(); let make_admin = *make_admin; + let new_pwd_state = new_pwd.clone(); let new_pwd = (*new_pwd).clone(); saving.set(true); @@ -600,6 +601,7 @@ pub fn user_by_id_component(props: &UserProps) -> Html { if let Ok(updated) = resp.json::().await { user_state.set(Some(updated)); } + new_pwd_state.set(String::new()); save_success.set(true); } Ok(resp) => { diff --git a/frontend/src/styles/components/_icon.scss b/frontend/src/styles/components/_icon.scss new file mode 100644 index 0000000..28272fe --- /dev/null +++ b/frontend/src/styles/components/_icon.scss @@ -0,0 +1,17 @@ +.csg-icon { + position: fixed; + top: 1rem; + right: 1rem; + z-index: 9999; + width: auto; + height: auto; + display: flex; + align-items: center; + justify-content: center; + padding: 0; + + img { + width: auto; + height: auto; + } +} diff --git a/frontend/src/styles/main.scss b/frontend/src/styles/main.scss index 97eb764..706057e 100644 --- a/frontend/src/styles/main.scss +++ b/frontend/src/styles/main.scss @@ -6,6 +6,7 @@ @use "components/diagnostics"; @use "components/frontpage"; @use "components/home"; +@use "components/icon"; body { background: variables.$color-bg; @@ -73,4 +74,4 @@ body { button { margin: 16px 0; } -} \ No newline at end of file +}