Implement Two-factor authentification

This commit is contained in:
coolneng 2020-10-31 14:20:46 +01:00
parent 5a3afd0bfa
commit e3ab194c06
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 22 additions and 1 deletions

View File

@ -1,6 +1,15 @@
import logging
from telethon import TelegramClient, events from telethon import TelegramClient, events
from telethon.sessions import StringSession from telethon.sessions import StringSession
from constants import API_ID, API_HASH, BOT_TOKEN, SESSION
from constants import API_HASH, API_ID, BOT_TOKEN, CSV_FILE, SESSION
from database import search_csv
from notifier import send_mail
logging.basicConfig(
format="[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s", level=logging.WARNING
)
bot = TelegramClient(StringSession(SESSION), API_ID, API_HASH).start( bot = TelegramClient(StringSession(SESSION), API_ID, API_HASH).start(
bot_token=BOT_TOKEN bot_token=BOT_TOKEN
@ -15,6 +24,18 @@ async def start(event):
raise events.StopPropagation raise events.StopPropagation
@bot.on(events.NewMessage(pattern=r"^[0-9]{8,8}[A-Za-z]"))
@bot.on(
events.NewMessage(pattern=r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)")
)
async def identify(event):
user = search_csv(filepath=CSV_FILE, id=event.raw_text)
send_mail(recipient=user["correo_institucional"])
await event.respond(
"El usuario se ha identificado con éxito. Se ha mandado una clave alfanumérica a su correo institucional. Por favor envíe la clave para continuar con el proceso."
)
def main(): def main():
bot.run_until_disconnected() bot.run_until_disconnected()