From 4cc42697cb5bd15bfaaeee45b30201d7d8dacc80 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 20 Sep 2026 19:41:02 -0400 Subject: [PATCH] cargo fmt --- src/callers/login.rs | 42 ++++++++++++++++++++++++++++++------------ src/repo/mod.rs | 32 +++++++++++++++++++------------- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 1494cff..9e2f43f 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -35,7 +35,11 @@ pub mod request { impl Request { pub fn is_valid(&self) -> bool { - !self.user_id.is_nil() || !self.username.is_empty() || !self.current_password.is_empty() || !self.updated_password.is_empty() || !self.confirmed_password.is_empty() + !self.user_id.is_nil() + || !self.username.is_empty() + || !self.current_password.is_empty() + || !self.updated_password.is_empty() + || !self.confirmed_password.is_empty() } } } @@ -320,18 +324,30 @@ pub mod endpoint { match repo::user::get(&pool, &payload.username).await { Ok(user) => { - if hashing::verify_password(&payload.current_password, user.password.clone()).unwrap() { + if hashing::verify_password(&payload.current_password, user.password.clone()) + .unwrap() + { match repo::salt::get(&pool, &user.salt_id).await { Ok(salt) => { let updated_salt_string = hashing::generate_salt().unwrap(); let mut updated_salt = simodels::user::salt::Salt::default(); updated_salt.salt = updated_salt_string.to_string(); updated_salt.id = salt.id.clone(); - let updated_hashed_password = hashing::hash_password(&payload.updated_password, &updated_salt_string).unwrap(); + let updated_hashed_password = hashing::hash_password( + &payload.updated_password, + &updated_salt_string, + ) + .unwrap(); match repo::salt::update_salt(&pool, &salt, &updated_salt.salt).await { Ok(_) => { - match repo::user::update_password(&pool, &user, &updated_hashed_password).await { + match repo::user::update_password( + &pool, + &user, + &updated_hashed_password, + ) + .await + { Ok(_) => { response.message = "Successful".to_string(); response.data.push(user.id); @@ -339,13 +355,10 @@ pub mod endpoint { } Err(err) => { response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } - } - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + ( + axum::http::StatusCode::BAD_REQUEST, + axum::Json(response), + ) } } } @@ -354,7 +367,12 @@ pub mod endpoint { (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } } - + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } } else { response.message = "Invalid".to_string(); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) diff --git a/src/repo/mod.rs b/src/repo/mod.rs index bd6b397..a5ed496 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -44,25 +44,30 @@ pub mod user { } } - pub async fn update_password(pool: &sqlx::PgPool, user: &simodels::user::User, password: &str) -> Result { + pub async fn update_password( + pool: &sqlx::PgPool, + user: &simodels::user::User, + password: &str, + ) -> Result { match sqlx::query( r#" UPDATE "user" SET password = $1 WHERE id = $2 - "# + "#, ) .bind(password) .bind(user.id) .execute(pool) // .fetch_optional(pool) - .await { + .await + { Ok(r) => { return if r.rows_affected() > 0 { Ok(true) } else { Ok(false) - } + }; } - Err(err) => Err(err) + Err(err) => Err(err), } } @@ -219,7 +224,11 @@ pub mod salt { } } - pub async fn update_salt(pool: &sqlx::PgPool, salt: &simodels::user::salt::Salt, updated_salt: &str) -> Result { + pub async fn update_salt( + pool: &sqlx::PgPool, + salt: &simodels::user::salt::Salt, + updated_salt: &str, + ) -> Result { match sqlx::query( r#" UPDATE "salt" SET salt = $1 WHERE id = $2 @@ -228,16 +237,13 @@ pub mod salt { .bind(updated_salt) .bind(salt.id) .execute(pool) - .await { + .await + { Ok(row) => { - let result = if row.rows_affected() > 0 { - true - } else { - false - }; + let result = if row.rows_affected() > 0 { true } else { false }; Ok(result) - }, + } Err(err) => Err(err), } }