Saving changes
This commit is contained in:
@@ -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#"
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user