Trim username

This commit is contained in:
Martin Brodbeck 2025-01-09 08:40:35 +01:00
parent 1461a83fa7
commit 9f23a778d5

View file

@ -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<PgPool>, headers: HeaderMap) -> (StatusCode, Json<Value>) {
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<UpdateProgress>,
) -> 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<String>,
) -> (StatusCode, Json<Value>) {
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();