More code

This commit is contained in:
2026-09-20 19:40:45 -04:00
parent 53ed0060c8
commit 1a885274a8
2 changed files with 42 additions and 11 deletions
+10 -2
View File
@@ -323,13 +323,14 @@ 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::salt::update_salt(&pool, &salt, &updated_salt.salt).await {
Ok(_) => {
match repo::user::update_password(&pool, &user, &updated_hashed_password).await {
Ok(_) => {
response.message = "Successful".to_string();
@@ -343,12 +344,19 @@ 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))
}
}
} else {
// invalid
response.message = "Invalid".to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
}
+23
View File
@@ -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<bool, sqlx::Error> {
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),
}
}
}