Compare commits

..

2 commits

Author SHA1 Message Date
a6c1c65900 code cleanup 2025-01-09 08:47:39 +01:00
9f23a778d5 Trim username 2025-01-09 08:40:35 +01:00

View file

@ -87,10 +87,7 @@ async fn create_user(
State(db_pool): State<PgPool>,
Json(payload): Json<User>,
) -> (StatusCode, Json<Value>) {
//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 +134,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 +156,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 +202,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();