Further cleanup

This commit is contained in:
Lonami Exo 2018-01-11 12:38:02 +01:00
parent 836309e4a6
commit 294aa814c2

View File

@ -247,21 +247,17 @@ 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())
break
# raises SessionPasswordNeededError if 2FA enabled
me = self.sign_in(phone, provided_code)
if me:
break
except SessionPasswordNeededError: except SessionPasswordNeededError:
two_step_detected = True two_step_detected = True
break break
@ -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(