More code
This commit is contained in:
+19
-11
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user