From e2cd7a52cf4ab2e7d3cc7590b3b8b932c3e0d736 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 20 Sep 2026 19:50:03 -0400 Subject: [PATCH] More stuff --- src/callers/login.rs | 5 +++-- src/main.rs | 42 +++++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 9e2f43f..199082b 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -305,7 +305,8 @@ pub mod endpoint { ), responses( (status = 200, description = "Password updated successfully", body = super::response::update_password::Response), - (status = 400, description = "Failure", body = super::response::update_password::Response) + (status = 400, description = "Invalid", body = super::response::update_password::Response), + (status = 500, description = "Failure", body = super::response::update_password::Response) ) )] pub async fn update_password( @@ -356,7 +357,7 @@ pub mod endpoint { Err(err) => { response.message = err.to_string(); ( - axum::http::StatusCode::BAD_REQUEST, + axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response), ) } diff --git a/src/main.rs b/src/main.rs index 71ef3ba..3627802 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,11 +38,11 @@ mod init { paths( common_callers::endpoint::db_ping, common_callers::endpoint::root, register_caller::register_user, - login_endpoints::login, login_endpoints::service_login, login_endpoints::refresh_token + login_endpoints::login, login_endpoints::update_password, login_endpoints::service_login, login_endpoints::refresh_token ), components(schemas(common_callers::response::TestResult, register_responses::Response, - login_responses::Response, login_responses::service_login::Response, login_responses::refresh_token::Response)), + login_responses::Response, login_responses::service_login::Response, login_responses::update_password::Response, login_responses::refresh_token::Response)), tags( (name = "soaricarus Auth API", description = "Auth API for soaricarus API") ) @@ -51,20 +51,20 @@ mod init { mod cors { pub async fn configure_cors() -> tower_http::cors::CorsLayer { - // Start building the CORS layer with common settings let cors = tower_http::cors::CorsLayer::new() .allow_methods([ axum::http::Method::GET, + axum::http::Method::PATCH, axum::http::Method::POST, axum::http::Method::PUT, axum::http::Method::DELETE, - ]) // Specify allowed methods:cite[2] + ]) .allow_headers([ axum::http::header::CONTENT_TYPE, axum::http::header::AUTHORIZATION, - ]) // Specify allowed headers:cite[2] - .allow_credentials(true) // If you need to send cookies or authentication headers:cite[2] - .max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2] + ]) + .allow_credentials(true) + .max_age(std::time::Duration::from_secs(3600)); // Dynamically set the allowed origin based on the environment match std::env::var(sienvy::keys::APP_ENV).as_deref() { @@ -116,6 +116,10 @@ mod init { callers::endpoints::LOGIN, post(callers::login::endpoint::login), ) + .route( + callers::endpoints::UPDATE_PASSWORD, + post(callers::login::endpoint::update_password), + ) .route( callers::endpoints::SERVICE_LOGIN, post(callers::login::endpoint::service_login), @@ -553,4 +557,28 @@ mod tests { let _ = db_mgr::drop_database(&tm_pool, &db_name).await; } + + #[tokio::test] + async fn test_update_password() { + let tm_pool = db_mgr::get_pool().await.unwrap(); + + let db_name = db_mgr::generate_db_name().await; + + match db_mgr::create_database(&tm_pool, &db_name).await { + Ok(_) => { + println!("Success"); + } + Err(e) => { + assert!(false, "Error: {:?}", e.to_string()); + } + } + + let pool = db_mgr::connect_to_db(&db_name).await.unwrap(); + + db::init::migrations(&pool).await; + + let app = init::routes().await.layer(axum::Extension(pool)); + + let _ = db_mgr::drop_database(&tm_pool, &db_name).await; + } }