add status

This commit is contained in:
jb-alvarado 2022-06-08 18:16:58 +02:00
parent cca5e24cc9
commit cac4e25620

View File

@ -1,4 +1,4 @@
use actix_web::{get, post, web, Responder}; use actix_web::{get, http::StatusCode, post, web, Responder};
use argon2::{password_hash::PasswordHash, Argon2, PasswordVerifier}; use argon2::{password_hash::PasswordHash, Argon2, PasswordVerifier};
use serde::Serialize; use serde::Serialize;
use simplelog::*; use simplelog::*;
@ -38,6 +38,8 @@ pub async fn login(credentials: web::Json<User>) -> impl Responder {
status: 200, status: 200,
data: Some(user), data: Some(user),
}) })
.customize()
.with_status(StatusCode::OK)
} else { } else {
error!("Wrong password for {}!", credentials.username); error!("Wrong password for {}!", credentials.username);
web::Json(ResponseObj { web::Json(ResponseObj {
@ -45,15 +47,19 @@ pub async fn login(credentials: web::Json<User>) -> impl Responder {
status: 401, status: 401,
data: None, data: None,
}) })
.customize()
.with_status(StatusCode::FORBIDDEN)
} }
} }
Err(e) => { Err(e) => {
error!("Login {} failed! {e}", credentials.username); error!("Login {} failed! {e}", credentials.username);
return web::Json(ResponseObj { return web::Json(ResponseObj {
message: format!("Login {} failed!", credentials.username), message: format!("Login {} failed!", credentials.username),
status: 404, status: 400,
data: None, data: None,
}); })
.customize()
.with_status(StatusCode::BAD_REQUEST);
} }
} }
} }