Maybe this time
Rust Build / Check (pull_request) Failing after 11s
Rust Build / Test Suite (pull_request) Successful in 53s
Rust Build / Rustfmt (pull_request) Successful in 1m21s
Rust Build / Clippy (pull_request) Successful in 1m46s
Rust Build / build (pull_request) Successful in 2m1s

This commit is contained in:
2026-06-11 17:51:15 -04:00
parent e1f2bff832
commit e4f6e95a79
2 changed files with 50 additions and 23 deletions
+14 -10
View File
@@ -45,7 +45,8 @@ pub mod response {
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)] #[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
pub struct ServiceUserLoginResponse { pub struct ServiceUserLoginResponse {
pub message: String, pub message: String,
pub data: Vec<textsender_models::user::ServiceUser>, // TODO: Change this to login result
pub data: Vec<textsender_models::token::LoginResult>,
} }
pub async fn extract( pub async fn extract(
@@ -208,7 +209,10 @@ pub async fn user_login(
pub async fn service_user_login( pub async fn service_user_login(
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::Json(payload): axum::Json<request::ServiceUserLoginRequest>, axum::Json(payload): axum::Json<request::ServiceUserLoginRequest>,
) -> (axum::http::StatusCode, axum::Json<response::LoginResponse>) { ) -> (
axum::http::StatusCode,
axum::Json<response::ServiceUserLoginResponse>,
) {
if payload.username.is_empty() || payload.passphrase.is_empty() { if payload.username.is_empty() || payload.passphrase.is_empty() {
let reason = if payload.username.is_empty() { let reason = if payload.username.is_empty() {
String::from("Username not provided") String::from("Username not provided")
@@ -218,7 +222,7 @@ pub async fn service_user_login(
( (
axum::http::StatusCode::BAD_REQUEST, axum::http::StatusCode::BAD_REQUEST,
axum::Json(response::LoginResponse { axum::Json(response::ServiceUserLoginResponse {
message: reason, message: reason,
data: Vec::new(), data: Vec::new(),
}), }),
@@ -230,7 +234,7 @@ pub async fn service_user_login(
println!("User does not exists"); println!("User does not exists");
( (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::LoginResponse { axum::Json(response::ServiceUserLoginResponse {
message: String::from("Unable to login"), message: String::from("Unable to login"),
data: Vec::new(), data: Vec::new(),
}), }),
@@ -244,7 +248,7 @@ pub async fn service_user_login(
eprintln!("Error: {err:?}"); eprintln!("Error: {err:?}");
return ( return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::LoginResponse { axum::Json(response::ServiceUserLoginResponse {
message: String::from("Unable to login"), message: String::from("Unable to login"),
data: Vec::new(), data: Vec::new(),
}), }),
@@ -278,7 +282,7 @@ pub async fn service_user_login(
( (
axum::http::StatusCode::OK, axum::http::StatusCode::OK,
axum::Json(response::LoginResponse { axum::Json(response::ServiceUserLoginResponse {
message: String::from( message: String::from(
super::messages::SUCCESSFUL_MESSAGE, super::messages::SUCCESSFUL_MESSAGE,
), ),
@@ -297,7 +301,7 @@ pub async fn service_user_login(
eprintln!("Invalid token"); eprintln!("Invalid token");
( (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::LoginResponse { axum::Json(response::ServiceUserLoginResponse {
message: String::from("Invalid attempt"), message: String::from("Invalid attempt"),
data: Vec::new(), data: Vec::new(),
}), }),
@@ -307,7 +311,7 @@ pub async fn service_user_login(
eprintln!("No match"); eprintln!("No match");
( (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::LoginResponse { axum::Json(response::ServiceUserLoginResponse {
message: String::from("Invalid attempt"), message: String::from("Invalid attempt"),
data: Vec::new(), data: Vec::new(),
}), }),
@@ -316,7 +320,7 @@ pub async fn service_user_login(
} }
Err(err) => ( Err(err) => (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::LoginResponse { axum::Json(response::ServiceUserLoginResponse {
message: err.to_string(), message: err.to_string(),
data: Vec::new(), data: Vec::new(),
}), }),
@@ -326,7 +330,7 @@ pub async fn service_user_login(
} }
Err(err) => ( Err(err) => (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::LoginResponse { axum::Json(response::ServiceUserLoginResponse {
message: err.to_string(), message: err.to_string(),
data: Vec::new(), data: Vec::new(),
}), }),
+36 -13
View File
@@ -221,13 +221,16 @@ async fn login_user(
response.status() response.status()
))) )))
} else { } else {
match axum::body::to_bytes(response.into_body(), usize::MAX).await { match convert_response::<callers::login::response::LoginResponse>(response).await {
Ok(body) => { Ok(response) => {
let parsed_body: callers::login::response::LoginResponse = if response.data.len() > 0 {
serde_json::from_slice(&body).unwrap(); let user = response.data[0].clone();
Ok(parsed_body.data[0].clone()) Ok(user)
} else {
Err(std::io::Error::other("No data returned"))
}
} }
Err(err) => Err(std::io::Error::other(err.to_string())), Err(err) => Err(err),
} }
} }
} }
@@ -246,8 +249,19 @@ async fn register_service_user(
response.status() response.status()
))) )))
} else { } else {
match convert_response::<textsender_models::user::ServiceUser>(response).await { match convert_response::<callers::register::response::RegisterServiceUserResponse>(
Ok(service_user) => Ok(service_user), response,
)
.await
{
Ok(response) => {
if response.data.len() > 0 {
let service_user = response.data[0].clone();
Ok(service_user)
} else {
Err(std::io::Error::other("No data returned"))
}
}
Err(err) => Err(err), Err(err) => Err(err),
} }
} }
@@ -256,7 +270,7 @@ async fn register_service_user(
} }
} }
async fn _login_service_user( async fn login_service_user(
app: &axum::Router, app: &axum::Router,
username: &str, username: &str,
passphrase: &str, passphrase: &str,
@@ -269,8 +283,19 @@ async fn _login_service_user(
response.status() response.status()
))) )))
} else { } else {
match convert_response::<textsender_models::token::LoginResult>(response).await { match convert_response::<callers::login::response::ServiceUserLoginResponse>(
Ok(service_user) => Ok(service_user), response,
)
.await
{
Ok(response) => {
if response.data.len() > 0 {
let login_result = response.data[0].clone();
Ok(login_result)
} else {
Err(std::io::Error::other("No data returned"))
}
}
Err(err) => Err(err), Err(err) => Err(err),
} }
} }
@@ -445,7 +470,6 @@ async fn test_login_service_user() {
user.id.is_nil(), user.id.is_nil(),
"The service user id should not be nil" "The service user id should not be nil"
); );
/*
match login_service_user(&app, TEST_SERVICE_USERNAME, TEST_SERVICE_PASSPHRASE).await { match login_service_user(&app, TEST_SERVICE_USERNAME, TEST_SERVICE_PASSPHRASE).await {
Ok(login_result) => { Ok(login_result) => {
assert_eq!( assert_eq!(
@@ -458,7 +482,6 @@ async fn test_login_service_user() {
assert!(false, "Error: {err:?}"); assert!(false, "Error: {err:?}");
} }
} }
*/
} }
Err(err) => { Err(err) => {
assert!(false, "Error: {err:?}"); assert!(false, "Error: {err:?}");