70 lines
1.8 KiB
Rust
70 lines
1.8 KiB
Rust
use crate::{change_state, prelude::*};
|
|
use teloxide::types::ParseMode;
|
|
use tokio::task::spawn_blocking;
|
|
|
|
#[inline]
|
|
async fn get_master_pass(
|
|
bot: Throttle<Bot>,
|
|
msg: Message,
|
|
db: DatabaseConnection,
|
|
dialogue: MainDialogue,
|
|
mut ids: MessageIds,
|
|
name: String,
|
|
master_pass: String,
|
|
) -> crate::Result<()> {
|
|
dialogue.exit().await?;
|
|
|
|
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
|
|
|
let account = match Account::get(user_id, &name, &db).await? {
|
|
Some(account) => account,
|
|
None => {
|
|
bot.send_message(msg.chat.id, "Account not found")
|
|
.reply_markup(deletion_markup())
|
|
.await?;
|
|
return Ok(());
|
|
}
|
|
};
|
|
|
|
let (login, password) = spawn_blocking(move || account.decrypt(&master_pass)).await??;
|
|
let text = format!("Name:\n`{name}`\nLogin:\n`{login}`\nPassword:\n`{password}`");
|
|
|
|
ids.alter_message(
|
|
&bot,
|
|
text,
|
|
account_markup(&name, false),
|
|
ParseMode::MarkdownV2,
|
|
)
|
|
.await?;
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn decrypt(
|
|
bot: Throttle<Bot>,
|
|
q: CallbackQuery,
|
|
db: DatabaseConnection,
|
|
dialogue: MainDialogue,
|
|
hash: super::NameHash,
|
|
) -> crate::Result<()> {
|
|
let mut msg: MessageIds = q.message.as_ref().unwrap().into();
|
|
let user_id = q.from.id.0;
|
|
let name = match name_from_hash(&db, user_id, &hash).await? {
|
|
Some(name) => name,
|
|
None => {
|
|
msg.alter_message(
|
|
&bot,
|
|
"Account wan't found. Select another one",
|
|
menu_markup("decrypt", user_id, &db).await?,
|
|
None,
|
|
)
|
|
.await?;
|
|
return Ok(());
|
|
}
|
|
};
|
|
|
|
msg.alter_message(&bot, "Send master password", None, None)
|
|
.await?;
|
|
|
|
change_state!(dialogue, msg, (name), State::GetMasterPass, get_master_pass)
|
|
}
|