1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2024-12-26 07:38:36 -06:00

fix: Use proper HTTP response codes

This commit is contained in:
Sayantan Santra 2024-04-03 16:19:39 -05:00
parent 231fd3c8ca
commit e742c0ab5e
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F

View file

@ -30,12 +30,12 @@ async fn add_link(req: String, data: web::Data<AppState>, session: Session) -> H
if auth::validate(session) { if auth::validate(session) {
let out = utils::add_link(req, &data.db); let out = utils::add_link(req, &data.db);
if out.0 { if out.0 {
HttpResponse::Ok().body(out.1) HttpResponse::Created().body(out.1)
} else { } else {
HttpResponse::BadRequest().body(out.1) HttpResponse::Conflict().body(out.1)
} }
} else { } else {
HttpResponse::Forbidden().body("Not logged in!") HttpResponse::Unauthorized().body("Not logged in!")
} }
} }
@ -45,7 +45,7 @@ async fn getall(data: web::Data<AppState>, session: Session) -> HttpResponse {
if auth::validate(session) { if auth::validate(session) {
HttpResponse::Ok().body(utils::getall(&data.db)) HttpResponse::Ok().body(utils::getall(&data.db))
} else { } 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")); let site_url = env::var("site_url").unwrap_or(String::from("unset"));
HttpResponse::Ok().body(site_url) HttpResponse::Ok().body(site_url)
} else { } 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 let Ok(password) = env::var("password") {
if password != req { if password != req {
eprintln!("Failed login attempt!"); 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 // Return Ok if no password was set on the server side
@ -127,7 +127,7 @@ async fn delete_link(
HttpResponse::NotFound().body("Not found!") HttpResponse::NotFound().body("Not found!")
} }
} else { } else {
HttpResponse::Forbidden().body("Not logged in!") HttpResponse::Unauthorized().body("Not logged in!")
} }
} }