Updated altering accounts to handle errors
This commit is contained in:
parent
2eff5f3f4e
commit
ff1d5a039d
@ -130,7 +130,7 @@ impl Account {
|
|||||||
original_name: &str,
|
original_name: &str,
|
||||||
new_name: &str,
|
new_name: &str,
|
||||||
pool: &Pool,
|
pool: &Pool,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<bool> {
|
||||||
query!(
|
query!(
|
||||||
"UPDATE account SET name = ? WHERE user_id = ? AND name = ?",
|
"UPDATE account SET name = ? WHERE user_id = ? AND name = ?",
|
||||||
new_name,
|
new_name,
|
||||||
@ -139,7 +139,7 @@ impl Account {
|
|||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await
|
.await
|
||||||
.map(|_| ())
|
.map(|result| result.rows_affected() != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -148,7 +148,7 @@ impl Account {
|
|||||||
name: &str,
|
name: &str,
|
||||||
login: Vec<u8>,
|
login: Vec<u8>,
|
||||||
pool: &Pool,
|
pool: &Pool,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<bool> {
|
||||||
query!(
|
query!(
|
||||||
"UPDATE account SET enc_login = ? WHERE user_id = ? AND name = ?",
|
"UPDATE account SET enc_login = ? WHERE user_id = ? AND name = ?",
|
||||||
login,
|
login,
|
||||||
@ -157,7 +157,7 @@ impl Account {
|
|||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await
|
.await
|
||||||
.map(|_| ())
|
.map(|result| result.rows_affected() != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -166,7 +166,7 @@ impl Account {
|
|||||||
name: &str,
|
name: &str,
|
||||||
password: Vec<u8>,
|
password: Vec<u8>,
|
||||||
pool: &Pool,
|
pool: &Pool,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<bool> {
|
||||||
query!(
|
query!(
|
||||||
"UPDATE account SET enc_password = ? WHERE user_id = ? AND name = ?",
|
"UPDATE account SET enc_password = ? WHERE user_id = ? AND name = ?",
|
||||||
password,
|
password,
|
||||||
@ -175,6 +175,6 @@ impl Account {
|
|||||||
)
|
)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await
|
.await
|
||||||
.map(|_| ())
|
.map(|result| result.rows_affected() != 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,6 @@ account_not_found: "Account wasn't found"
|
|||||||
send_new_name: "Send new name"
|
send_new_name: "Send new name"
|
||||||
send_new_login: "Send new login"
|
send_new_login: "Send new login"
|
||||||
send_new_password: "Send new password"
|
send_new_password: "Send new password"
|
||||||
success_choose_account_to_view: "Success. Chose an account to view"
|
|
||||||
send_json_file: "Send the json file to import"
|
send_json_file: "Send the json file to import"
|
||||||
send_master_pass_to_delete_everything: "Send master password to delete EVERY ACCOUNT. THIS ACTION CANNOT BE UNDONE"
|
send_master_pass_to_delete_everything: "Send master password to delete EVERY ACCOUNT. THIS ACTION CANNOT BE UNDONE"
|
||||||
everything_was_deleted: "Every account was deleted"
|
everything_was_deleted: "Every account was deleted"
|
||||||
|
@ -66,7 +66,6 @@ account_not_found: "Аккаунт не найден"
|
|||||||
send_new_name: "Отправьте новое название"
|
send_new_name: "Отправьте новое название"
|
||||||
send_new_login: "Отправьте новый логин"
|
send_new_login: "Отправьте новый логин"
|
||||||
send_new_password: "Отправьте новый пароль"
|
send_new_password: "Отправьте новый пароль"
|
||||||
success_choose_account_to_view: "Успешно. Выберите аккаунт для просмотра"
|
|
||||||
send_json_file: "Отправьте файл json для импорта"
|
send_json_file: "Отправьте файл json для импорта"
|
||||||
send_master_pass_to_delete_everything: "Отправьте мастер-пароль, чтобы удалить ВСЕ АККАУНТЫ. ЭТО ДЕЙСТВИЕ НЕЛЬЗЯ ОТМЕНИТЬ"
|
send_master_pass_to_delete_everything: "Отправьте мастер-пароль, чтобы удалить ВСЕ АККАУНТЫ. ЭТО ДЕЙСТВИЕ НЕЛЬЗЯ ОТМЕНИТЬ"
|
||||||
everything_was_deleted: "Все аккаунты были удалены"
|
everything_was_deleted: "Все аккаунты были удалены"
|
||||||
|
@ -11,14 +11,16 @@ async fn update_account(
|
|||||||
field: AlterableField,
|
field: AlterableField,
|
||||||
field_value: String,
|
field_value: String,
|
||||||
master_pass: String,
|
master_pass: String,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<bool> {
|
||||||
if field == Name {
|
if field == Name {
|
||||||
Account::update_name(user_id, &name, &field_value, db).await?;
|
return Account::update_name(user_id, &name, &field_value, db)
|
||||||
|
.await
|
||||||
return Ok(());
|
.map_err(Into::into);
|
||||||
}
|
}
|
||||||
|
|
||||||
let salt = Account::get_salt(user_id, &name, db).await?.unwrap();
|
let Some(salt) = Account::get_salt(user_id, &name, db).await? else {
|
||||||
|
return Ok(false);
|
||||||
|
};
|
||||||
|
|
||||||
let field_value = spawn_blocking(move || {
|
let field_value = spawn_blocking(move || {
|
||||||
let cipher = Cipher::new(master_pass.as_bytes(), &salt);
|
let cipher = Cipher::new(master_pass.as_bytes(), &salt);
|
||||||
@ -28,13 +30,13 @@ async fn update_account(
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
match field {
|
let updated = match field {
|
||||||
Login => Account::update_login(user_id, &name, field_value, db).await?,
|
Login => Account::update_login(user_id, &name, field_value, db).await?,
|
||||||
Pass => Account::update_password(user_id, &name, field_value, db).await?,
|
Pass => Account::update_password(user_id, &name, field_value, db).await?,
|
||||||
Name => unreachable!(),
|
Name => unreachable!(),
|
||||||
}
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -54,15 +56,17 @@ async fn get_master_pass(
|
|||||||
dialogue.exit().await?;
|
dialogue.exit().await?;
|
||||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||||
|
|
||||||
update_account(user_id, &db, name, field, field_value, master_pass).await?;
|
let text = match update_account(user_id, &db, name, field, field_value, master_pass).await {
|
||||||
|
Ok(true) => locale.success.as_str(),
|
||||||
|
Ok(false) => &locale.account_not_found,
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("{err:?}");
|
||||||
|
&locale.something_went_wrong
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ids.alter_message(
|
ids.alter_message(&bot, text, deletion_markup(locale), None)
|
||||||
&bot,
|
.await?;
|
||||||
&locale.success_choose_account_to_view,
|
|
||||||
menu_markup("get", user_id, &db).await?,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -82,7 +86,7 @@ pub async fn alter(
|
|||||||
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
|
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
|
||||||
|
|
||||||
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
|
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
|
||||||
bot.send_message(ids.0, "Account wasn't found")
|
bot.send_message(ids.0, &locale.account_not_found)
|
||||||
.reply_markup(deletion_markup(locale))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
bot.answer_callback_query(q.id).await?;
|
bot.answer_callback_query(q.id).await?;
|
||||||
|
@ -96,7 +96,6 @@ pub struct Locale {
|
|||||||
pub send_new_name: LocaleString,
|
pub send_new_name: LocaleString,
|
||||||
pub send_new_login: LocaleString,
|
pub send_new_login: LocaleString,
|
||||||
pub send_new_password: LocaleString,
|
pub send_new_password: LocaleString,
|
||||||
pub success_choose_account_to_view: LocaleString,
|
|
||||||
pub send_json_file: LocaleString,
|
pub send_json_file: LocaleString,
|
||||||
pub send_master_pass_to_delete_everything: LocaleString,
|
pub send_master_pass_to_delete_everything: LocaleString,
|
||||||
pub everything_was_deleted: LocaleString,
|
pub everything_was_deleted: LocaleString,
|
||||||
|
Loading…
Reference in New Issue
Block a user