From 9f23a778d55dbe414c3c0621d7e5568ca3bd1947 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 9 Jan 2025 08:40:35 +0100 Subject: [PATCH] Trim username --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index bbf116f..f75d992 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,7 +90,7 @@ async fn create_user( //let client = redis::Client::open("redis://127.0.0.1/").unwrap(); //let mut con = client.get_connection().unwrap(); - let username = payload.username; + let username = payload.username.trim().to_owned(); let password = payload.password; let row: (i64,) = sqlx::query_as("SELECT COUNT(id) FROM users WHERE username = $1") @@ -137,7 +137,7 @@ async fn authorize(db: impl PgExecutor<'_>, username: &str, password: &str) -> b } async fn auth_user(State(db_pool): State, headers: HeaderMap) -> (StatusCode, Json) { - let username = headers["x-auth-user"].to_str().unwrap_or(""); + let username = headers["x-auth-user"].to_str().unwrap_or("").trim(); let password = headers["x-auth-key"].to_str().unwrap_or(""); let mut tx = db_pool.begin().await.unwrap(); @@ -159,7 +159,7 @@ async fn update_progress( headers: HeaderMap, Json(payload): Json, ) -> StatusCode { - let username = headers["x-auth-user"].to_str().unwrap_or(""); + let username = headers["x-auth-user"].to_str().unwrap_or("").trim(); let password = headers["x-auth-key"].to_str().unwrap_or(""); let mut tx = db_pool.begin().await.unwrap(); @@ -205,7 +205,7 @@ async fn get_progress( headers: HeaderMap, Path(document): Path, ) -> (StatusCode, Json) { - let username = headers["x-auth-user"].to_str().unwrap_or(""); + let username = headers["x-auth-user"].to_str().unwrap_or("").trim(); let password = headers["x-auth-key"].to_str().unwrap_or(""); let mut tx = db_pool.begin().await.unwrap();