mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-29 09:53:07 +03:00
Fix start() and sign_up() flow for layer 104
This commit is contained in:
parent
00b0319397
commit
42874de2b2
|
@ -133,7 +133,7 @@ class AuthMethods:
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _start(
|
async def _start(
|
||||||
self, phone, password, bot_token, force_sms,
|
self: 'TelegramClient', phone, password, bot_token, force_sms,
|
||||||
code_callback, first_name, last_name, max_attempts):
|
code_callback, first_name, last_name, max_attempts):
|
||||||
if not self.is_connected():
|
if not self.is_connected():
|
||||||
await self.connect()
|
await self.connect()
|
||||||
|
@ -163,8 +163,8 @@ class AuthMethods:
|
||||||
attempts = 0
|
attempts = 0
|
||||||
two_step_detected = False
|
two_step_detected = False
|
||||||
|
|
||||||
sent_code = await self.send_code_request(phone, force_sms=force_sms)
|
await self.send_code_request(phone, force_sms=force_sms)
|
||||||
sign_up = not sent_code.phone_registered
|
sign_up = False # assume login
|
||||||
while attempts < max_attempts:
|
while attempts < max_attempts:
|
||||||
try:
|
try:
|
||||||
value = code_callback()
|
value = code_callback()
|
||||||
|
@ -261,7 +261,7 @@ class AuthMethods:
|
||||||
*,
|
*,
|
||||||
password: str = None,
|
password: str = None,
|
||||||
bot_token: str = None,
|
bot_token: str = None,
|
||||||
phone_code_hash: str = None) -> 'types.User':
|
phone_code_hash: str = None) -> 'typing.Union[types.User, types.auth.SentCode]':
|
||||||
"""
|
"""
|
||||||
Logs in to Telegram to an existing user or bot account.
|
Logs in to Telegram to an existing user or bot account.
|
||||||
|
|
||||||
|
@ -323,24 +323,31 @@ class AuthMethods:
|
||||||
|
|
||||||
# May raise PhoneCodeEmptyError, PhoneCodeExpiredError,
|
# May raise PhoneCodeEmptyError, PhoneCodeExpiredError,
|
||||||
# PhoneCodeHashEmptyError or PhoneCodeInvalidError.
|
# PhoneCodeHashEmptyError or PhoneCodeInvalidError.
|
||||||
result = await self(functions.auth.SignInRequest(
|
request = functions.auth.SignInRequest(
|
||||||
phone, phone_code_hash, str(code)))
|
phone, phone_code_hash, str(code)
|
||||||
|
)
|
||||||
elif password:
|
elif password:
|
||||||
pwd = await self(functions.account.GetPasswordRequest())
|
pwd = await self(functions.account.GetPasswordRequest())
|
||||||
result = await self(functions.auth.CheckPasswordRequest(
|
request = functions.auth.CheckPasswordRequest(
|
||||||
pwd_mod.compute_check(pwd, password)
|
pwd_mod.compute_check(pwd, password)
|
||||||
))
|
)
|
||||||
elif bot_token:
|
elif bot_token:
|
||||||
result = await self(functions.auth.ImportBotAuthorizationRequest(
|
request = functions.auth.ImportBotAuthorizationRequest(
|
||||||
flags=0, bot_auth_token=bot_token,
|
flags=0, bot_auth_token=bot_token,
|
||||||
api_id=self.api_id, api_hash=self.api_hash
|
api_id=self.api_id, api_hash=self.api_hash
|
||||||
))
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'You must provide a phone and a code the first time, '
|
'You must provide a phone and a code the first time, '
|
||||||
'and a password only if an RPCError was raised before.'
|
'and a password only if an RPCError was raised before.'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
result = await self(request)
|
||||||
|
if isinstance(result, types.auth.AuthorizationSignUpRequired):
|
||||||
|
# Emulate pre-layer 104 behaviour
|
||||||
|
self._tos = result.terms_of_service
|
||||||
|
raise errors.PhoneNumberUnoccupiedError(request=request)
|
||||||
|
|
||||||
return self._on_login(result.user)
|
return self._on_login(result.user)
|
||||||
|
|
||||||
async def sign_up(
|
async def sign_up(
|
||||||
|
@ -411,7 +418,6 @@ class AuthMethods:
|
||||||
result = await self(functions.auth.SignUpRequest(
|
result = await self(functions.auth.SignUpRequest(
|
||||||
phone_number=phone,
|
phone_number=phone,
|
||||||
phone_code_hash=phone_code_hash,
|
phone_code_hash=phone_code_hash,
|
||||||
phone_code=str(code),
|
|
||||||
first_name=first_name,
|
first_name=first_name,
|
||||||
last_name=last_name
|
last_name=last_name
|
||||||
))
|
))
|
||||||
|
@ -475,7 +481,6 @@ class AuthMethods:
|
||||||
except errors.AuthRestartError:
|
except errors.AuthRestartError:
|
||||||
return await self.send_code_request(phone, force_sms=force_sms)
|
return await self.send_code_request(phone, force_sms=force_sms)
|
||||||
|
|
||||||
self._tos = result.terms_of_service
|
|
||||||
self._phone_code_hash[phone] = phone_hash = result.phone_code_hash
|
self._phone_code_hash[phone] = phone_hash = result.phone_code_hash
|
||||||
else:
|
else:
|
||||||
force_sms = True
|
force_sms = True
|
||||||
|
|
Loading…
Reference in New Issue
Block a user