Fix Two-Factor-Authentification. Add minor tweaks to authview. Close #5

This commit is contained in:
Dominic Zimmer 2019-09-11 11:40:00 +02:00
parent f2f78cf0fd
commit 2ab8dac662

View File

@ -22,6 +22,7 @@ class AuthView():
self.inputs = "" self.inputs = ""
self.w, self.h = curses.COLS, curses.LINES self.w, self.h = curses.COLS, curses.LINES
self.fin = False self.fin = False
self.showinput = True
async def textinput(self): async def textinput(self):
@ -47,7 +48,7 @@ class AuthView():
self.stdscr.refresh() self.stdscr.refresh()
self.phone = await self.textinput() self.phone = await self.textinput()
try: try:
response = await self.client.send_code_request(self.phone) response = await self.client.send_code_request(self.phone.replace("+","00").replace(" ",""))
if not response.phone_registered: if not response.phone_registered:
self.stdscr.addstr("This phone number is not registered in telegram. ") self.stdscr.addstr("This phone number is not registered in telegram. ")
self.stdscr.refresh() self.stdscr.refresh()
@ -59,24 +60,27 @@ class AuthView():
except Exception as e: except Exception as e:
self.stdscr.addstr("Incorrect phone number. ") self.stdscr.addstr("Incorrect phone number. ")
self.stdscr.refresh() self.stdscr.refresh()
self.stdscr.addstr("auth with code now.") self.stdscr.addstr("Now authentificate with the code telegram sent to you.")
self.stdscr.refresh() self.stdscr.refresh()
self.code = await self.textinput() while True:
try:
await self.client.sign_in(self.phone, self.code)
except telethon.errors.SessionPasswordNeededError:
self.stdscr.addstr("Password required to log in")
self.stdscr.refresh()
self.passwd = await self.textinput()
try: try:
await self.client.sign_in(password=self.passwd) self.code = await self.textinput()
# TODO: debug me await self.client.sign_in(self.phone.replace("+","00").replace(" ",""), self.code)
except: except telethon.errors.rpcerrorlist.PhoneCodeInvalidError:
show_stacktrace() self.stdscr.addstr("The authentification code was wrong. Please try again.")
except telethon.errors.rpcerrorlist.PhoneCodeInvalidError: self.stdscr.refresh()
pass except telethon.errors.SessionPasswordNeededError:
self.showinput = False
self.stdscr.addstr(f"auth successful. ") self.stdscr.addstr("A 2FA password is required to log in.")
self.stdscr.refresh()
while True:
self.passwd = await self.textinput()
try:
await self.client.sign_in(password=self.passwd)
except telethon.errors.PasswordHashInvalidError:
self.stdscr.addstr("Incorrect password. Try again.")
self.stdscr.refresh()
self.stdscr.addstr("Authentification successfull. Please wait until the client has finished loading.")
self.stdscr.refresh() self.stdscr.refresh()
async def handle_key(self, key): async def handle_key(self, key):
@ -87,7 +91,10 @@ class AuthView():
self.inputs = self.inputs[0:-1] self.inputs = self.inputs[0:-1]
else: else:
self.inputs += key self.inputs += key
self.stdscr.addstr(20, 50, self.inputs) if self.showinput:
self.stdscr.addstr(20, 50, self.inputs)
else:
self.stdscr.addstr(20, 50, "*"*len(self.inputs))
self.stdscr.clrtoeol() self.stdscr.clrtoeol()
self.stdscr.refresh() self.stdscr.refresh()