From 649b9135c6bcd91598c7935349a7c4effcf8be15 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Thu, 23 Mar 2023 15:13:08 +0200 Subject: [PATCH] fix(api, server, shared): dont do drugs and api --- api/src/handlers/user/info.rs | 12 ++++++++---- server/src/systems/event/message/mod.rs | 7 +++++-- shared/src/api/user/mod.rs | 10 +++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/api/src/handlers/user/info.rs b/api/src/handlers/user/info.rs index ab39053..38a236c 100644 --- a/api/src/handlers/user/info.rs +++ b/api/src/handlers/user/info.rs @@ -12,19 +12,23 @@ use laurelin_shared::error::api::APIError; use crate::{actions, session, PgPool}; -#[get("/api/user")] -pub(crate) async fn info(pool: web::Data, session: Session) -> impl Responder { +#[get("/api/user/{id}")] +pub(crate) async fn info( + pool: web::Data, + session: Session, + id: web::Path, +) -> impl Responder { let session_validation = session::validate_session(&session); match session_validation { Err(err) => err, - Ok(user_id) => { + Ok(_user_id) => { let user_details = web::block(move || { let mut conn = match pool.get() { Err(_) => return Err(APIError::DatabasePoolGetFailed), Ok(conn) => conn, }; - actions::user::info(&mut conn, &user_id) + actions::user::info(&mut conn, &id) }) .await; match user_details { diff --git a/server/src/systems/event/message/mod.rs b/server/src/systems/event/message/mod.rs index 7963146..3377e7e 100644 --- a/server/src/systems/event/message/mod.rs +++ b/server/src/systems/event/message/mod.rs @@ -119,8 +119,11 @@ pub(crate) fn message_events( DataRequestType::PubUserDetails => { // TODO: handle let cookie = global.user_to_session_map.get(&user_key).unwrap(); - let wrapped = - user::info(&config.api_address, &request.data.unwrap_or("".to_string())); + let wrapped = user::info( + &config.api_address, + &request.data.unwrap_or("".to_string()), + cookie, + ); let user_details = match wrapped.response { ResponseInfo::Error(_err) => { panic!("I can't be bothered to handle this right now.") diff --git a/shared/src/api/user/mod.rs b/shared/src/api/user/mod.rs index 1db7531..985f051 100644 --- a/shared/src/api/user/mod.rs +++ b/shared/src/api/user/mod.rs @@ -6,7 +6,7 @@ * See LICENSE for licensing information. */ -use reqwest; +use reqwest::{self, header::COOKIE}; use serde::{Deserialize, Serialize}; use crate::{error::api::APIError, types::user::UserPub}; @@ -26,10 +26,14 @@ pub struct ResponseInfoWrapper { pub cookie: String, } -pub fn info(api_address: &str, user_id: &str) -> ResponseInfoWrapper { +pub fn info(api_address: &str, user_id: &str, cookie: &str) -> ResponseInfoWrapper { let client = reqwest::blocking::Client::new(); - let resp = client.get(&format!("{}/user", api_address)).send().unwrap(); + let resp = client + .get(&format!("{}/user/{}", api_address, user_id)) + .header(COOKIE, &format!("id={}", cookie)) + .send() + .unwrap(); ResponseInfoWrapper { cookie: extract_cookie!(resp), -- 2.44.1