added get endpoint, updated state_management

This commit is contained in:
2023-07-26 00:52:12 +03:00
parent 96c7d2e37e
commit 22c754a256
27 changed files with 278 additions and 149 deletions

View File

@ -8,11 +8,13 @@ async fn get_master_pass(
msg: Message,
db: DatabaseConnection,
dialogue: MainDialogue,
ids: MessageIds,
name: String,
login: String,
password: String,
master_pass: String,
) -> crate::Result<()> {
ids.delete(&bot).await;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
dialogue.exit().await?;
let account = spawn_blocking(move || {
@ -38,4 +40,9 @@ handler!(get_login(name: String, login: String),
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);
first_handler!(
add_account,
"Send account name",
State::GetNewName,
get_account_name
);

View File

@ -7,10 +7,13 @@ async fn get_master_pass(
msg: Message,
db: DatabaseConnection,
dialogue: MainDialogue,
ids: MessageIds,
name: String,
_: String,
) -> crate::Result<()> {
ids.delete(&bot).await;
dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
Account::delete_by_id((user_id, name)).exec(&db).await?;
bot.send_message(msg.chat.id, "The account is successfully deleted")
@ -25,4 +28,8 @@ handler!(
State::GetMasterPass,
get_master_pass
);
ask_name_handler!(pub delete(), "Send the name of the account to delete", get_account_name);
ask_name_handler!(
delete,
"Send the name of the account to delete",
get_account_name
);

View File

@ -10,8 +10,10 @@ async fn get_master_pass(
msg: Message,
db: DatabaseConnection,
dialogue: MainDialogue,
ids: MessageIds,
_: String,
) -> crate::Result<()> {
ids.delete(&bot).await;
dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
let txn = db.begin().await?;
@ -36,8 +38,8 @@ async fn get_master_pass(
Ok(())
}
handler!(
pub delete_all(),
first_handler!(
delete_all,
"Send master password to delete EVERYTHING.\nTHIS ACTION IS IRREVERSIBLE",
State::GetMasterPass,
get_master_pass

View File

@ -23,8 +23,10 @@ async fn get_master_pass(
msg: Message,
db: DatabaseConnection,
dialogue: MainDialogue,
ids: MessageIds,
master_pass: String,
) -> crate::Result<()> {
ids.delete(&bot).await;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
let mut accounts = Vec::new();
@ -53,4 +55,9 @@ async fn get_master_pass(
Ok(())
}
handler!(pub export(), "Send the master password to export your accounts", State::GetMasterPass, get_master_pass);
first_handler!(
export,
"Send the master password to export your accounts",
State::GetMasterPass,
get_master_pass
);

View File

@ -8,10 +8,13 @@ async fn get_master_pass(
msg: Message,
db: DatabaseConnection,
dialogue: MainDialogue,
ids: MessageIds,
name: String,
master_pass: String,
) -> crate::Result<()> {
ids.delete(&bot).await;
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,
@ -32,4 +35,8 @@ async fn get_master_pass(
}
handler!(get_account_name(name:String), "Send master password", State::GetMasterPass, get_master_pass);
ask_name_handler!(pub get_account(), "Send the name of the account to get", get_account_name);
ask_name_handler!(
get_account,
"Send the name of the account to get",
get_account_name
);

View File

@ -31,9 +31,11 @@ async fn get_master_pass(
msg: Message,
db: DatabaseConnection,
dialogue: MainDialogue,
ids: MessageIds,
user: User,
master_pass: String,
) -> crate::Result<()> {
ids.delete(&bot).await;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
let mut failed = Vec::new();
@ -64,4 +66,9 @@ async fn get_master_pass(
}
handler!(get_user(user: User), "Send master password", State::GetMasterPass, get_master_pass);
handler!(pub import(), "Send a json document with the same format as created by /export", State::GetUser, get_user);
first_handler!(
import,
"Send a json document with the same format as created by /export",
State::GetUser,
get_user
);

View File

@ -15,7 +15,7 @@ pub async fn menu(bot: Throttle<Bot>, msg: Message, db: DatabaseConnection) -> c
.await?;
}
let markup = spawn_blocking(|| menu_markup(names)).await?;
let markup = spawn_blocking(|| menu_markup_sync(names)).await?;
bot.send_message(msg.chat.id, "Choose your account")
.reply_markup(markup)
.await?;

View File

@ -7,9 +7,12 @@ async fn get_master_pass(
msg: Message,
db: DatabaseConnection,
dialogue: MainDialogue,
ids: MessageIds,
master_pass: String,
) -> crate::Result<()> {
ids.delete(&bot).await;
dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
let model =
spawn_blocking(move || master_pass::ActiveModel::from_unencrypted(user_id, &master_pass))
@ -40,10 +43,10 @@ pub async fn set_master_pass(
.await?;
dialogue
.update(State::GetNewMasterPass(Handler::new(
|bot, msg, db, dialogue, master_pass| {
Box::pin(get_master_pass(bot, msg, db, dialogue, master_pass))
|bot, msg, db, dialogue, ids, master_pass| {
Box::pin(get_master_pass(bot, msg, db, dialogue, ids, master_pass))
},
&previous,
MessageIds::from(&previous),
)))
.await?;
Ok(())