mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-09-19 18:32:47 +03:00
Further cleanup
This commit is contained in:
parent
836309e4a6
commit
294aa814c2
|
@ -247,20 +247,16 @@ class TelegramClient(TelegramBareClient):
|
||||||
self.sign_in(bot_token=bot_token)
|
self.sign_in(bot_token=bot_token)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
two_step_detected = False
|
|
||||||
self.send_code_request(phone, force_sms)
|
|
||||||
|
|
||||||
me = None
|
me = None
|
||||||
attempts = 0
|
attempts = 0
|
||||||
max_attempts = 3
|
max_attempts = 3
|
||||||
|
two_step_detected = False
|
||||||
|
|
||||||
|
self.send_code_request(phone, force_sms=force_sms)
|
||||||
while attempts < max_attempts:
|
while attempts < max_attempts:
|
||||||
try:
|
try:
|
||||||
# Normal login
|
# Raises SessionPasswordNeededError if 2FA enabled
|
||||||
provided_code = str(code_callback())
|
me = self.sign_in(phone, code_callback())
|
||||||
|
|
||||||
# raises SessionPasswordNeededError if 2FA enabled
|
|
||||||
me = self.sign_in(phone, provided_code)
|
|
||||||
if me:
|
|
||||||
break
|
break
|
||||||
except SessionPasswordNeededError:
|
except SessionPasswordNeededError:
|
||||||
two_step_detected = True
|
two_step_detected = True
|
||||||
|
@ -319,7 +315,7 @@ class TelegramClient(TelegramBareClient):
|
||||||
:meth:`.send_code_request()`.
|
:meth:`.send_code_request()`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if phone and not code:
|
if phone and not code and not password:
|
||||||
return self.send_code_request(phone)
|
return self.send_code_request(phone)
|
||||||
elif code:
|
elif code:
|
||||||
phone = utils.parse_phone(phone) or self._phone
|
phone = utils.parse_phone(phone) or self._phone
|
||||||
|
@ -333,15 +329,9 @@ class TelegramClient(TelegramBareClient):
|
||||||
if not phone_code_hash:
|
if not phone_code_hash:
|
||||||
raise ValueError('You also need to provide a phone_code_hash.')
|
raise ValueError('You also need to provide a phone_code_hash.')
|
||||||
|
|
||||||
try:
|
# May raise PhoneCodeEmptyError, PhoneCodeExpiredError,
|
||||||
if isinstance(code, int):
|
# PhoneCodeHashEmptyError or PhoneCodeInvalidError.
|
||||||
code = str(code)
|
result = self(SignInRequest(phone, phone_code_hash, str(code)))
|
||||||
|
|
||||||
result = self(SignInRequest(phone, phone_code_hash, code))
|
|
||||||
|
|
||||||
except (PhoneCodeEmptyError, PhoneCodeExpiredError,
|
|
||||||
PhoneCodeHashEmptyError, PhoneCodeInvalidError) as e:
|
|
||||||
raise e # Hand responsibility to the user
|
|
||||||
elif password:
|
elif password:
|
||||||
salt = self(GetPasswordRequest()).current_salt
|
salt = self(GetPasswordRequest()).current_salt
|
||||||
result = self(CheckPasswordRequest(
|
result = self(CheckPasswordRequest(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user