Saving changes

This commit is contained in:
2026-06-12 12:13:01 -04:00
parent 0115f96671
commit 74b9f90f57
4 changed files with 237 additions and 1 deletions
+25
View File
@@ -104,6 +104,31 @@ pub mod user {
}
}
pub async fn update_password(
pool: &sqlx::PgPool,
user: &textsender_models::user::User,
updated_hashed_password: &String,
) -> Result<(), sqlx::Error> {
match sqlx::query(
r#"
UPDATE "user" SET password = $1 WHERE id = $2
"#,
)
.bind(updated_hashed_password)
.bind(user.id)
.execute(pool)
.await {
Ok(row) => {
if row.rows_affected() > 0 {
Ok(())
} else {
Err(sqlx::Error::RowNotFound)
}
}
Err(err) => Err(err),
}
}
pub async fn exists(pool: &sqlx::PgPool, username: &String) -> Result<bool, sqlx::Error> {
let result = sqlx::query(
r#"
+25
View File
@@ -154,6 +154,31 @@ pub async fn update_last_login(
}
}
pub async fn update_passphrase(
pool: &sqlx::PgPool,
user: &textsender_models::user::ServiceUser,
updated_hashed_passphrase: &String,
) -> Result<(), sqlx::Error> {
match sqlx::query(
r#"
UPDATE "service_user" SET passphrase = $1 WHERE id = $2
"#,
)
.bind(updated_hashed_passphrase)
.bind(user.id)
.execute(pool)
.await {
Ok(row) => {
if row.rows_affected() > 0 {
Ok(())
} else {
Err(sqlx::Error::RowNotFound)
}
}
Err(err) => Err(err),
}
}
pub async fn insert(
pool: &sqlx::PgPool,
service_user: &textsender_models::user::ServiceUser,