From f7d90e4a098e94fcbd82430b53d4c406d1eafd80 Mon Sep 17 00:00:00 2001 From: shockrah Date: Tue, 30 Mar 2021 21:36:21 -0700 Subject: [PATCH] - Removal of auth code in db-lib --- json-api/db/src/auth.rs | 35 ----------------------------------- json-api/db/src/lib.rs | 3 +-- 2 files changed, 1 insertion(+), 37 deletions(-) delete mode 100644 json-api/db/src/auth.rs diff --git a/json-api/db/src/auth.rs b/json-api/db/src/auth.rs deleted file mode 100644 index 5df7208..0000000 --- a/json-api/db/src/auth.rs +++ /dev/null @@ -1,35 +0,0 @@ -use mysql_async::{params, Pool}; -use mysql_async::prelude::Queryable; -use mysql_async::error::Error; -use crate::UBigInt; - -async fn update_jwt(p: &Pool, id: UBigInt, token: &str) -> Result<(), Error> { - let conn = p.get_conn().await?; - let _ = conn.drop_exec("UPDATE jwt SET token = :tk WHERE id = :id", - params!{"tk" => token, "id" => id}).await?; - Ok(()) -} - -pub async fn add_jwt(p: &Pool, id: UBigInt, token: &str) -> Result<(), Error> { - let conn = p.get_conn().await?; - let q = "INSERT INTO jwt (id, token) VALUES (:id, :tk)"; - return match conn.prep_exec(q, params!{"tk" => token, "id" => id}).await { - Ok(_) => Ok(()), - Err(_) => update_jwt(p, id, token).await // attempt to refresh token - }; -} - -pub async fn listed_jwt(p: &Pool, id: UBigInt, token_given: &str) -> Result { - // only checks if the given token is listed somewhere in the db - let conn = p.get_conn().await?; - let q = "SELECT token FROM jwt WHERE id = :id"; - // if id.token == return true - let (_, db_t): (_, Option) = - conn.first_exec(q, params!{"id" => id}).await?; - - - return match db_t { - Some(token_db) => Ok(token_db == token_given), // probably pointless check but its not that expensive so its stays as a sanity check - None => Ok(false) - }; -} \ No newline at end of file diff --git a/json-api/db/src/lib.rs b/json-api/db/src/lib.rs index c5b39b0..d0503b2 100644 --- a/json-api/db/src/lib.rs +++ b/json-api/db/src/lib.rs @@ -5,7 +5,6 @@ pub mod common; pub mod invites; pub mod channels; pub mod messages; -pub mod auth; use std::vec::Vec; @@ -35,7 +34,7 @@ pub enum Response { } #[allow(dead_code)] -#[derive(Serialize)] +#[derive(Debug, Serialize)] pub struct Message { pub id: UBigInt, pub time: BigInt,