@ -7,7 +7,7 @@ import telebot
from sqlalchemy . future import Engine
from sqlalchemy . future import Engine
from telebot . async_telebot import AsyncTeleBot
from telebot . async_telebot import AsyncTeleBot
from . . import d b, encryption , generate_password
from . . import d ata base , encryption , generate_password
from . . account_checks import (
from . . account_checks import (
check_account ,
check_account ,
check_account_name ,
check_account_name ,
@ -36,7 +36,7 @@ async def get_accounts(
mes : Message ,
mes : Message ,
) - > None :
) - > None :
await base_handler ( bot , mes )
await base_handler ( bot , mes )
accounts = d b. get . get_accounts (
accounts = d ata base . get . get_accounts (
engine ,
engine ,
mes . from_user . id ,
mes . from_user . id ,
to_sort = True ,
to_sort = True ,
@ -73,8 +73,8 @@ async def _delete_all2(
await base_handler ( bot , mes , prev_mes )
await base_handler ( bot , mes , prev_mes )
text = mes . text . strip ( )
text = mes . text . strip ( )
if text == " YES " :
if text == " YES " :
d b. delete . purge_accounts ( engine , mes . from_user . id )
d ata base . delete . purge_accounts ( engine , mes . from_user . id )
d b. delete . delete_master_pass ( engine , mes . from_user . id )
d ata base . delete . delete_master_pass ( engine , mes . from_user . id )
await send_tmp_message (
await send_tmp_message (
bot ,
bot ,
mes . chat . id ,
mes . chat . id ,
@ -95,7 +95,7 @@ async def set_master_password(
mes : Message ,
mes : Message ,
) - > None :
) - > None :
await base_handler ( bot , mes , None )
await base_handler ( bot , mes , None )
if d b. get . get_master_pass ( engine , mes . from_user . id ) is not None :
if d ata base . get . get_master_pass ( engine , mes . from_user . id ) is not None :
return await send_tmp_message (
return await send_tmp_message (
bot ,
bot ,
mes . chat . id ,
mes . chat . id ,
@ -120,7 +120,7 @@ async def _set_master_pass2(
mes . from_user . id ,
mes . from_user . id ,
text ,
text ,
)
)
d b. add . add_master_pass ( engine , master_password )
d ata base . add . add_master_pass ( engine , master_password )
await send_tmp_message ( bot , mes . chat . id , " Успех " )
await send_tmp_message ( bot , mes . chat . id , " Успех " )
del mes , text
del mes , text
@ -134,7 +134,7 @@ async def reset_master_pass(
) - > None :
) - > None :
await base_handler ( bot , mes )
await base_handler ( bot , mes )
if d b. get . get_master_pass ( engine , mes . from_user . id ) is None :
if d ata base . get . get_master_pass ( engine , mes . from_user . id ) is None :
return await send_tmp_message (
return await send_tmp_message (
bot ,
bot ,
mes . chat . id ,
mes . chat . id ,
@ -165,8 +165,8 @@ async def _reset_master_pass2(
mes . from_user . id ,
mes . from_user . id ,
text ,
text ,
)
)
d b. delete . purge_accounts ( engine , mes . from_user . id )
d ata base . delete . purge_accounts ( engine , mes . from_user . id )
d b. change . change_master_pass ( engine , master_password )
d ata base . change . change_master_pass ( engine , master_password )
await send_tmp_message (
await send_tmp_message (
bot , mes . chat . id , " В с е ваши аккаунты удалены, а мастер пароль изменён"
bot , mes . chat . id , " В с е ваши аккаунты удалены, а мастер пароль изменён"
@ -178,7 +178,7 @@ async def _reset_master_pass2(
async def add_account ( bot : AsyncTeleBot , engine : Engine , mes : Message ) - > None :
async def add_account ( bot : AsyncTeleBot , engine : Engine , mes : Message ) - > None :
await base_handler ( bot , mes )
await base_handler ( bot , mes )
master_password_from_db = d b. get . get_master_pass (
master_password_from_db = d ata base . get . get_master_pass (
engine ,
engine ,
mes . from_user . id ,
mes . from_user . id ,
)
)
@ -210,7 +210,7 @@ async def _add_account2(
mes . chat . id ,
mes . chat . id ,
" Н е корректное название аккаунта" ,
" Н е корректное название аккаунта" ,
)
)
if text in d b. get . get_accounts ( engine , mes . from_user . id ) :
if text in d ata base . get . get_accounts ( engine , mes . from_user . id ) :
return await send_tmp_message (
return await send_tmp_message (
bot , mes . chat . id , " Аккаунт с таким именем уже существует "
bot , mes . chat . id , " Аккаунт с таким именем уже существует "
)
)
@ -291,7 +291,7 @@ async def _add_account5(
if text == " /cancel " :
if text == " /cancel " :
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
master_password = d b. get . get_master_pass ( engine , mes . from_user . id )
master_password = d ata base . get . get_master_pass ( engine , mes . from_user . id )
if not encryption . master_pass . check_master_pass ( text , master_password ) :
if not encryption . master_pass . check_master_pass ( text , master_password ) :
return await send_tmp_message (
return await send_tmp_message (
bot ,
bot ,
@ -307,9 +307,12 @@ async def _add_account5(
password = data [ " passwd " ] ,
password = data [ " passwd " ] ,
)
)
encrypted_account = encryption . accounts . encrypt ( account , text )
encrypted_account = encryption . accounts . encrypt (
account ,
text ,
)
result = db . add . add_account (
result = d ata base . add . add_account (
engine ,
engine ,
encrypted_account ,
encrypted_account ,
)
)
@ -328,11 +331,11 @@ async def _add_account5(
async def get_account ( bot : AsyncTeleBot , engine : Engine , mes : Message ) - > None :
async def get_account ( bot : AsyncTeleBot , engine : Engine , mes : Message ) - > None :
await base_handler ( bot , mes )
await base_handler ( bot , mes )
master_pass = d b. get . get_master_pass ( engine , mes . from_user . id )
master_pass = d ata base . get . get_master_pass ( engine , mes . from_user . id )
if master_pass is None :
if master_pass is None :
return await send_tmp_message ( bot , mes . chat . id , " Нет мастер пароля " )
return await send_tmp_message ( bot , mes . chat . id , " Нет мастер пароля " )
accounts = d b. get . get_accounts (
accounts = d ata base . get . get_accounts (
engine ,
engine ,
mes . from_user . id ,
mes . from_user . id ,
to_sort = True ,
to_sort = True ,
@ -355,7 +358,7 @@ async def _get_account2(
if text == " /cancel " :
if text == " /cancel " :
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
if text not in d b. get . get_accounts ( engine , mes . from_user . id ) :
if text not in d ata base . get . get_accounts ( engine , mes . from_user . id ) :
return await send_tmp_message ( bot , mes . chat . id , " Нет такого аккаунта " )
return await send_tmp_message ( bot , mes . chat . id , " Нет такого аккаунта " )
bot_mes = await bot . send_message ( mes . chat . id , " Отправьте мастер пароль " )
bot_mes = await bot . send_message ( mes . chat . id , " Отправьте мастер пароль " )
@ -377,7 +380,7 @@ async def _get_account3(
if text == " /cancel " :
if text == " /cancel " :
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
master_password = d b. get . get_master_pass (
master_password = d ata base . get . get_master_pass (
engine ,
engine ,
mes . from_user . id ,
mes . from_user . id ,
)
)
@ -389,8 +392,11 @@ async def _get_account3(
" Н е подходит мастер пароль" ,
" Н е подходит мастер пароль" ,
)
)
account = db . get . get_account_info ( engine , mes . from_user . id , name )
account = database . get . get_account_info ( engine , mes . from_user . id , name )
account = encryption . accounts . decrypt ( account , text )
account = encryption . accounts . decrypt (
account ,
text ,
)
await send_deleteable_message (
await send_deleteable_message (
bot ,
bot ,
mes . chat . id ,
mes . chat . id ,
@ -410,11 +416,11 @@ async def delete_account(
) - > None :
) - > None :
await base_handler ( bot , mes )
await base_handler ( bot , mes )
master_pass = d b. get . get_master_pass ( engine , mes . from_user . id )
master_pass = d ata base . get . get_master_pass ( engine , mes . from_user . id )
if master_pass is None :
if master_pass is None :
return await send_tmp_message ( bot , mes . chat . id , " Нет мастер пароля " )
return await send_tmp_message ( bot , mes . chat . id , " Нет мастер пароля " )
accounts = d b. get . get_accounts (
accounts = d ata base . get . get_accounts (
engine ,
engine ,
mes . from_user . id ,
mes . from_user . id ,
to_sort = True ,
to_sort = True ,
@ -443,7 +449,7 @@ async def _delete_account2(
if text == " /cancel " :
if text == " /cancel " :
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
if text not in d b. get . get_accounts ( engine , mes . from_user . id ) :
if text not in d ata base . get . get_accounts ( engine , mes . from_user . id ) :
return await send_tmp_message ( bot , mes . chat . id , " Нет такого аккаунта " )
return await send_tmp_message ( bot , mes . chat . id , " Нет такого аккаунта " )
bot_mes = await bot . send_message (
bot_mes = await bot . send_message (
@ -470,7 +476,7 @@ async def _delete_account3(
if text != " YES " :
if text != " YES " :
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
d b. delete . delete_account ( engine , mes . from_user . id , account_name )
d ata base . delete . delete_account ( engine , mes . from_user . id , account_name )
await send_tmp_message ( bot , mes . chat . id , " Аккаунт удалён " )
await send_tmp_message ( bot , mes . chat . id , " Аккаунт удалён " )
@ -494,7 +500,7 @@ async def help_command(bot: AsyncTeleBot, mes: Message) -> None:
async def export ( bot : AsyncTeleBot , engine : Engine , mes : Message ) - > None :
async def export ( bot : AsyncTeleBot , engine : Engine , mes : Message ) - > None :
await base_handler ( bot , mes )
await base_handler ( bot , mes )
master_password_from_db = d b. get . get_master_pass (
master_password_from_db = d ata base . get . get_master_pass (
engine ,
engine ,
mes . from_user . id ,
mes . from_user . id ,
)
)
@ -502,7 +508,7 @@ async def export(bot: AsyncTeleBot, engine: Engine, mes: Message) -> None:
if master_password_from_db is None :
if master_password_from_db is None :
return await send_tmp_message ( bot , mes . chat . id , " Нет мастер пароля " )
return await send_tmp_message ( bot , mes . chat . id , " Нет мастер пароля " )
if not d b. get . get_accounts ( engine , mes . from_user . id ) :
if not d ata base . get . get_accounts ( engine , mes . from_user . id ) :
return await send_tmp_message ( bot , mes . chat . id , " Нет аккаунтов " )
return await send_tmp_message ( bot , mes . chat . id , " Нет аккаунтов " )
bot_mes = await bot . send_message ( mes . chat . id , " Отправьте мастер пароль " )
bot_mes = await bot . send_message ( mes . chat . id , " Отправьте мастер пароль " )
@ -518,7 +524,7 @@ async def _export2(
if text == " /cancel " :
if text == " /cancel " :
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
master_password = d b. get . get_master_pass (
master_password = d ata base . get . get_master_pass (
engine ,
engine ,
mes . from_user . id ,
mes . from_user . id ,
)
)
@ -529,7 +535,7 @@ async def _export2(
" Н е подходит мастер пароль" ,
" Н е подходит мастер пароль" ,
)
)
accounts = d b. get . get_all_accounts ( engine , mes . from_user . id )
accounts = d ata base . get . get_all_accounts ( engine , mes . from_user . id )
with ProcessPoolExecutor ( ) as pool :
with ProcessPoolExecutor ( ) as pool :
loop = asyncio . get_running_loop ( )
loop = asyncio . get_running_loop ( )
tasks = [ ]
tasks = [ ]
@ -559,7 +565,7 @@ async def import_accounts(
mes : Message ,
mes : Message ,
) - > None :
) - > None :
await base_handler ( bot , mes )
await base_handler ( bot , mes )
master_password_from_db = d b. get . get_master_pass (
master_password_from_db = d ata base . get . get_master_pass (
engine ,
engine ,
mes . from_user . id ,
mes . from_user . id ,
)
)
@ -627,7 +633,7 @@ async def _import3(
if text == " /cancel " :
if text == " /cancel " :
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
return await send_tmp_message ( bot , mes . chat . id , " Успешная отмена " )
master_password = d b. get . get_master_pass (
master_password = d ata base . get . get_master_pass (
engine ,
engine ,
mes . from_user . id ,
mes . from_user . id ,
)
)
@ -645,8 +651,11 @@ async def _import3(
if not check_account ( account ) :
if not check_account ( account ) :
failed . append ( account . name )
failed . append ( account . name )
continue
continue
account = encryption . accounts . encrypt ( account , text )
account = encryption . accounts . encrypt (
result = db . add . add_account ( engine , account )
account ,
text ,
)
result = database . add . add_account ( engine , account )
if not result :
if not result :
failed . append ( account . name )
failed . append ( account . name )