Added Account::get method

This commit is contained in:
StNicolay 2023-05-06 20:37:26 +03:00
parent 71940762ff
commit 4a0760d711
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
2 changed files with 21 additions and 7 deletions

View File

@ -129,4 +129,17 @@ impl Entity {
.await?;
Ok(result.is_some())
}
pub async fn get(
user_id: u64,
account_name: impl Into<String>,
db: &DatabaseConnection,
) -> crate::Result<Option<Model>> {
Self::find()
.filter(Column::UserId.eq(user_id))
.filter(Column::Name.eq(account_name.into()))
.one(db)
.await
.map_err(Into::into)
}
}

View File

@ -1,5 +1,5 @@
use crate::{
entity::{account, prelude::Account},
entity::prelude::Account,
errors::NoUserInfo,
handlers::{markups, utils::package_handler, MainDialogue, State},
};
@ -19,12 +19,13 @@ async fn get_master_pass(
let _ = bot.delete_message(previous.chat.id, previous.id).await;
dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
let account = Account::find()
.filter(account::Column::UserId.eq(user_id))
.filter(account::Column::Name.eq(&name))
.one(&db)
.await?
.unwrap();
let account = match Account::get(user_id, &name, &db).await? {
Some(account) => account,
None => {
bot.send_message(msg.chat.id, "Account not found").await?;
return Ok(());
}
};
let (login, password) = spawn_blocking(move || account.decrypt(&master_pass)).await??;
let message = format!("Name:\n`{name}`\nLogin:\n`{login}`\nPassword:\n`{password}`");
bot.send_message(msg.chat.id, message)