From 7d7617783fa56e6fcb070795710cc948fdd1bd36 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Tue, 26 Sep 2023 21:42:21 +0200 Subject: [PATCH] authorize: improved return messge --- src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 22e0527..a905449 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,15 +101,18 @@ fn authorize(username: &str, password: &str) -> bool { true } -async fn auth_user(headers: HeaderMap) -> StatusCode { +async fn auth_user(headers: HeaderMap) -> (StatusCode, Json) { let username = headers["x-auth-user"].to_str().unwrap_or(""); let password = headers["x-auth-key"].to_str().unwrap_or(""); if authorize(&username, &password) == false { - return StatusCode::UNAUTHORIZED; + return ( + StatusCode::UNAUTHORIZED, + Json(json!({"message" : "Unauthorized"})), + ); } - StatusCode::OK + (StatusCode::OK, Json(json!({"authorized" : "OK"}))) } async fn update_progress(headers: HeaderMap, Json(payload): Json) -> StatusCode {