56 lines
1.3 KiB
Rust
56 lines
1.3 KiB
Rust
use crate::prelude::*;
|
|
use tokio::task::spawn_blocking;
|
|
|
|
/// Gets the name of the master password, encryptes the account and adds it to the DB
|
|
#[allow(clippy::too_many_arguments)]
|
|
async fn get_master_pass(
|
|
bot: Throttle<Bot>,
|
|
msg: Message,
|
|
db: Pool,
|
|
dialogue: MainDialogue,
|
|
mut ids: MessageIds,
|
|
locale: LocaleRef,
|
|
name: String,
|
|
login: String,
|
|
password: String,
|
|
master_pass: String,
|
|
) -> crate::Result<()> {
|
|
dialogue.exit().await?;
|
|
|
|
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
|
|
|
let account = spawn_blocking(move || {
|
|
DecryptedAccount {
|
|
name,
|
|
login,
|
|
password,
|
|
}
|
|
.into_account(user_id, &master_pass)
|
|
})
|
|
.await?;
|
|
account.insert(&db).await?;
|
|
|
|
ids.alter_message(&bot, &locale.success, deletion_markup(locale), None)
|
|
.await?;
|
|
Ok(())
|
|
}
|
|
|
|
handler!(
|
|
get_password(name:String, login: String, password: String),
|
|
send_master_password,
|
|
State::GetMasterPass,
|
|
get_master_pass
|
|
);
|
|
handler!(get_login(name: String, login: String),
|
|
send_password,
|
|
State::GetPassword,
|
|
get_password
|
|
);
|
|
handler!(get_account_name(name: String), send_login, State::GetLogin, get_login);
|
|
first_handler!(
|
|
add_account,
|
|
send_account_name,
|
|
State::GetNewName,
|
|
get_account_name
|
|
);
|