authorize: improved return messge

This commit is contained in:
Martin Brodbeck 2023-09-26 21:42:21 +02:00
parent 5d1b869124
commit 7d7617783f

View file

@ -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<Value>) {
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<UpdateProgress>) -> StatusCode {