mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Impl /auth/user/change/password
This commit is contained in:
@@ -434,10 +434,29 @@ impl PixivDownloaderSqlite {
|
||||
)?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
fn _update_user_name(ts: &Transaction, id: u64, name: &str) -> Result<usize, SqliteError> {
|
||||
Ok(ts.execute("UPDATE users SET name = ? WHERE id = ?;", (name, id))?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
fn _update_user_password(
|
||||
ts: &Transaction,
|
||||
id: u64,
|
||||
password: &[u8],
|
||||
token_id: u64,
|
||||
) -> Result<(), SqliteError> {
|
||||
ts.execute(
|
||||
"UPDATE users SET password = ? WHERE id = ?;",
|
||||
(password, id),
|
||||
)?;
|
||||
ts.execute(
|
||||
"DELETE FROM token WHERE user_id = ? AND id != ?;",
|
||||
(id, token_id),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn _write_version<'a>(&self, ts: &Transaction<'a>) -> Result<(), SqliteError> {
|
||||
let mut stmt = ts.prepare(
|
||||
"INSERT OR REPLACE INTO version (id, v1, v2, v3, v4) VALUES ('main', ?, ?, ?, ?);",
|
||||
@@ -608,4 +627,20 @@ impl PixivDownloaderDb for PixivDownloaderSqlite {
|
||||
}
|
||||
Ok(self.get_user(id).await?.expect("User not found:"))
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
async fn update_user_password(
|
||||
&self,
|
||||
id: u64,
|
||||
password: &[u8],
|
||||
token_id: u64,
|
||||
) -> Result<User, PixivDownloaderDbError> {
|
||||
{
|
||||
let mut db = self.db.lock().await;
|
||||
let mut tx = db.transaction()?;
|
||||
Self::_update_user_password(&mut tx, id, password, token_id)?;
|
||||
tx.commit()?;
|
||||
}
|
||||
Ok(self.get_user(id).await?.expect("User not found:"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,4 +116,17 @@ pub trait PixivDownloaderDb {
|
||||
/// * `id`: The user's ID
|
||||
/// * `name`: The user's name
|
||||
async fn update_user_name(&self, id: u64, name: &str) -> Result<User, PixivDownloaderDbError>;
|
||||
#[cfg(feature = "server")]
|
||||
/// Update a user's password
|
||||
/// * `id`: The user's ID
|
||||
/// * `password`: The user's hashed password
|
||||
/// * `token_id`: The token ID
|
||||
/// # Note
|
||||
/// All tokens of the user except token_id will be revoked
|
||||
async fn update_user_password(
|
||||
&self,
|
||||
id: u64,
|
||||
password: &[u8],
|
||||
token_id: u64,
|
||||
) -> Result<User, PixivDownloaderDbError>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user