From 1a885274a81ee006d6f62bb24d2bddb68300322d Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 20 Sep 2026 19:40:45 -0400 Subject: [PATCH] More code --- src/callers/login.rs | 30 +++++++++++++++++++----------- src/repo/mod.rs | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 4ce54d0..1494cff 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -323,32 +323,40 @@ pub mod endpoint { if hashing::verify_password(&payload.current_password, user.password.clone()).unwrap() { match repo::salt::get(&pool, &user.salt_id).await { Ok(salt) => { - // Left off here 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(); - match repo::user::update_password(&pool, &user, &updated_hashed_password).await { + match repo::salt::update_salt(&pool, &salt, &updated_salt.salt).await { Ok(_) => { - response.message = "Successful".to_string(); - response.data.push(user.id); - (axum::http::StatusCode::OK, axum::Json(response)) + match repo::user::update_password(&pool, &user, &updated_hashed_password).await { + Ok(_) => { + response.message = "Successful".to_string(); + response.data.push(user.id); + (axum::http::StatusCode::OK, axum::Json(response)) + } + 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)) + } + } } Err(err) => { response.message = err.to_string(); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } } - } - Err(err) => { - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } } else { - // invalid + 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 df5ac09..bd6b397 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -218,4 +218,27 @@ pub mod salt { Err(sqlx::Error::RowNotFound) } } + + 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 + "#, + ) + .bind(updated_salt) + .bind(salt.id) + .execute(pool) + .await { + Ok(row) => { + let result = if row.rows_affected() > 0 { + true + } else { + false + }; + + Ok(result) + }, + Err(err) => Err(err), + } + } }