From e742c0ab5efa34a6f3eaad872f6ff5a3b88c0088 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Wed, 3 Apr 2024 16:19:39 -0500 Subject: [PATCH] fix: Use proper HTTP response codes --- actix/src/main.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/actix/src/main.rs b/actix/src/main.rs index cbeebd4..f241c60 100644 --- a/actix/src/main.rs +++ b/actix/src/main.rs @@ -30,12 +30,12 @@ async fn add_link(req: String, data: web::Data, session: Session) -> H if auth::validate(session) { let out = utils::add_link(req, &data.db); if out.0 { - HttpResponse::Ok().body(out.1) + HttpResponse::Created().body(out.1) } else { - HttpResponse::BadRequest().body(out.1) + HttpResponse::Conflict().body(out.1) } } else { - HttpResponse::Forbidden().body("Not logged in!") + HttpResponse::Unauthorized().body("Not logged in!") } } @@ -45,7 +45,7 @@ async fn getall(data: web::Data, session: Session) -> HttpResponse { if auth::validate(session) { HttpResponse::Ok().body(utils::getall(&data.db)) } else { - HttpResponse::Forbidden().body("Not logged in!") + HttpResponse::Unauthorized().body("Not logged in!") } } @@ -56,7 +56,7 @@ async fn siteurl(session: Session) -> HttpResponse { let site_url = env::var("site_url").unwrap_or(String::from("unset")); HttpResponse::Ok().body(site_url) } else { - HttpResponse::Forbidden().body("Not logged in!") + HttpResponse::Unauthorized().body("Not logged in!") } } @@ -103,7 +103,7 @@ async fn login(req: String, session: Session) -> HttpResponse { if let Ok(password) = env::var("password") { if password != req { eprintln!("Failed login attempt!"); - return HttpResponse::Forbidden().body("Wrong password!"); + return HttpResponse::Unauthorized().body("Wrong password!"); } } // Return Ok if no password was set on the server side @@ -127,7 +127,7 @@ async fn delete_link( HttpResponse::NotFound().body("Not found!") } } else { - HttpResponse::Forbidden().body("Not logged in!") + HttpResponse::Unauthorized().body("Not logged in!") } }