pass_manager/src/commands/add_account.rs

42 lines
1.2 KiB
Rust
Raw Normal View History

use crate::prelude::*;
use tokio::task::spawn_blocking;
2023-05-03 18:08:14 +00:00
2023-05-09 17:27:58 +00:00
/// Gets the name of the master password, encryptes the account and adds it to the DB
2023-07-16 19:34:11 +00:00
#[allow(clippy::too_many_arguments)]
2023-05-03 18:08:14 +00:00
async fn get_master_pass(
bot: Throttle<Bot>,
msg: Message,
db: DatabaseConnection,
dialogue: MainDialogue,
2023-07-16 19:34:11 +00:00
name: String,
login: String,
password: String,
2023-05-03 18:08:14 +00:00
master_pass: String,
) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
2023-05-03 18:08:14 +00:00
dialogue.exit().await?;
2023-07-16 19:34:11 +00:00
let account = spawn_blocking(move || {
account::ActiveModel::from_unencrypted(user_id, name, &login, &password, &master_pass)
})
.await??;
2023-05-03 18:08:14 +00:00
account.insert(&db).await?;
bot.send_message(msg.chat.id, "Success")
.reply_markup(deletion_markup())
.await?;
2023-05-03 18:08:14 +00:00
Ok(())
}
2023-07-16 19:34:11 +00:00
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);
handler!(pub add_account(), "Send account name", State::GetNewName, get_account_name);