Add CLI command for password reset
This commit is contained in:
parent
8ad88f84b2
commit
9b96ce4700
4 changed files with 47 additions and 3 deletions
|
@ -25,6 +25,7 @@ async fn main() {
|
||||||
match subcmd {
|
match subcmd {
|
||||||
SubCommand::GenerateInviteCode(cmd) => cmd.execute(db_client).await.unwrap(),
|
SubCommand::GenerateInviteCode(cmd) => cmd.execute(db_client).await.unwrap(),
|
||||||
SubCommand::ListInviteCodes(cmd) => cmd.execute(db_client).await.unwrap(),
|
SubCommand::ListInviteCodes(cmd) => cmd.execute(db_client).await.unwrap(),
|
||||||
|
SubCommand::SetPassword(cmd) => cmd.execute(db_client).await.unwrap(),
|
||||||
SubCommand::RefetchActor(cmd) => cmd.execute(&config, db_client).await.unwrap(),
|
SubCommand::RefetchActor(cmd) => cmd.execute(&config, db_client).await.unwrap(),
|
||||||
SubCommand::DeleteProfile(cmd) => cmd.execute(&config, db_client).await.unwrap(),
|
SubCommand::DeleteProfile(cmd) => cmd.execute(&config, db_client).await.unwrap(),
|
||||||
SubCommand::DeletePost(cmd) => cmd.execute(&config, db_client).await.unwrap(),
|
SubCommand::DeletePost(cmd) => cmd.execute(&config, db_client).await.unwrap(),
|
||||||
|
|
27
src/cli.rs
27
src/cli.rs
|
@ -25,9 +25,14 @@ use crate::models::users::queries::{
|
||||||
create_invite_code,
|
create_invite_code,
|
||||||
get_invite_codes,
|
get_invite_codes,
|
||||||
get_user_by_id,
|
get_user_by_id,
|
||||||
|
set_user_password,
|
||||||
};
|
};
|
||||||
use crate::monero::wallet::create_monero_wallet;
|
use crate::monero::wallet::create_monero_wallet;
|
||||||
use crate::utils::crypto::{generate_private_key, serialize_private_key};
|
use crate::utils::crypto::{
|
||||||
|
hash_password,
|
||||||
|
generate_private_key,
|
||||||
|
serialize_private_key,
|
||||||
|
};
|
||||||
use crate::utils::files::remove_files;
|
use crate::utils::files::remove_files;
|
||||||
|
|
||||||
/// Admin CLI tool
|
/// Admin CLI tool
|
||||||
|
@ -44,6 +49,7 @@ pub enum SubCommand {
|
||||||
|
|
||||||
GenerateInviteCode(GenerateInviteCode),
|
GenerateInviteCode(GenerateInviteCode),
|
||||||
ListInviteCodes(ListInviteCodes),
|
ListInviteCodes(ListInviteCodes),
|
||||||
|
SetPassword(SetPassword),
|
||||||
RefetchActor(RefetchActor),
|
RefetchActor(RefetchActor),
|
||||||
DeleteProfile(DeleteProfile),
|
DeleteProfile(DeleteProfile),
|
||||||
DeletePost(DeletePost),
|
DeletePost(DeletePost),
|
||||||
|
@ -118,6 +124,25 @@ impl ListInviteCodes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set password
|
||||||
|
#[derive(Parser)]
|
||||||
|
pub struct SetPassword {
|
||||||
|
id: Uuid,
|
||||||
|
password: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SetPassword {
|
||||||
|
pub async fn execute(
|
||||||
|
&self,
|
||||||
|
db_client: &impl GenericClient,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let password_hash = hash_password(&self.password)?;
|
||||||
|
set_user_password(db_client, &self.id, password_hash).await?;
|
||||||
|
println!("password updated");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Re-fetch actor profile by actor ID
|
/// Re-fetch actor profile by actor ID
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct RefetchActor {
|
pub struct RefetchActor {
|
||||||
|
|
|
@ -780,7 +780,7 @@ pub async fn update_reaction_count(
|
||||||
).await?;
|
).await?;
|
||||||
if updated_count == 0 {
|
if updated_count == 0 {
|
||||||
return Err(DatabaseError::NotFound("post"));
|
return Err(DatabaseError::NotFound("post"));
|
||||||
}
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,7 +799,7 @@ pub async fn update_repost_count(
|
||||||
).await?;
|
).await?;
|
||||||
if updated_count == 0 {
|
if updated_count == 0 {
|
||||||
return Err(DatabaseError::NotFound("post"));
|
return Err(DatabaseError::NotFound("post"));
|
||||||
}
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,24 @@ pub async fn create_user(
|
||||||
Ok(user)
|
Ok(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn set_user_password(
|
||||||
|
db_client: &impl GenericClient,
|
||||||
|
user_id: &Uuid,
|
||||||
|
password_hash: String,
|
||||||
|
) -> Result<(), DatabaseError> {
|
||||||
|
let updated_count = db_client.execute(
|
||||||
|
"
|
||||||
|
UPDATE user_account SET password_hash = $1
|
||||||
|
WHERE id = $2
|
||||||
|
",
|
||||||
|
&[&password_hash, &user_id],
|
||||||
|
).await?;
|
||||||
|
if updated_count == 0 {
|
||||||
|
return Err(DatabaseError::NotFound("user"));
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_user_by_id(
|
pub async fn get_user_by_id(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
user_id: &Uuid,
|
user_id: &Uuid,
|
||||||
|
|
Loading…
Reference in a new issue