mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-20 13:31:00 +03:00
Remove phone and hash from sign_up
This commit is contained in:
parent
90bd5de74a
commit
1029c38d7e
|
@ -982,3 +982,4 @@ is_connected is now a property (consistent with the rest of ``is_`` properties)
|
||||||
send_code_request now returns a custom type (reducing raw api).
|
send_code_request now returns a custom type (reducing raw api).
|
||||||
sign_in no longer has phone or phone_hash (these are impl details, and now it's less error prone). also mandatory code=. also no longer is a no-op if already logged in. different error for sign up required.
|
sign_in no longer has phone or phone_hash (these are impl details, and now it's less error prone). also mandatory code=. also no longer is a no-op if already logged in. different error for sign up required.
|
||||||
send code / sign in now only expect a single phone. resend code with new phone is send code, not resend.
|
send code / sign in now only expect a single phone. resend code with new phone is send code, not resend.
|
||||||
|
sign_up code is also now a kwarg. and no longer noop if already loggedin.
|
||||||
|
|
|
@ -233,17 +233,17 @@ async def sign_in(
|
||||||
|
|
||||||
return await _update_session_state(self, result.user)
|
return await _update_session_state(self, result.user)
|
||||||
|
|
||||||
|
|
||||||
async def sign_up(
|
async def sign_up(
|
||||||
self: 'TelegramClient',
|
self: 'TelegramClient',
|
||||||
code: typing.Union[str, int],
|
|
||||||
first_name: str,
|
first_name: str,
|
||||||
last_name: str = '',
|
last_name: str = '',
|
||||||
*,
|
*,
|
||||||
phone: str = None,
|
code: typing.Union[str, int]) -> '_tl.User':
|
||||||
phone_code_hash: str = None) -> '_tl.User':
|
if not self._phone_code_hash:
|
||||||
me = await self.get_me()
|
raise ValueError('Must call client.send_code_request before sign up')
|
||||||
if me:
|
|
||||||
return me
|
phone, phone_code_hash = self._phone_code_hash
|
||||||
|
|
||||||
# To prevent abuse, one has to try to sign in before signing up. This
|
# To prevent abuse, one has to try to sign in before signing up. This
|
||||||
# is the current way in which Telegram validates the code to sign up.
|
# is the current way in which Telegram validates the code to sign up.
|
||||||
|
@ -259,18 +259,13 @@ async def sign_up(
|
||||||
code=code,
|
code=code,
|
||||||
phone_code_hash=phone_code_hash,
|
phone_code_hash=phone_code_hash,
|
||||||
)
|
)
|
||||||
except errors.PhoneNumberUnoccupiedError:
|
except errors.SignUpRequired:
|
||||||
pass # code is correct and was used, now need to sign in
|
pass # code is correct and was used, now need to sign in
|
||||||
|
|
||||||
if self._tos and self._tos.text:
|
if self._tos and self._tos.text:
|
||||||
sys.stderr.write("{}\n".format(self._tos.text))
|
sys.stderr.write("{}\n".format(self._tos.text))
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
if not self._phone_code_hash:
|
|
||||||
raise ValueError('Must call client.send_code_request before sign up')
|
|
||||||
|
|
||||||
phone, phone_code_hash = self._phone_code_hash
|
|
||||||
|
|
||||||
result = await self(_tl.fn.auth.SignUp(
|
result = await self(_tl.fn.auth.SignUp(
|
||||||
phone_number=phone,
|
phone_number=phone,
|
||||||
phone_code_hash=phone_code_hash,
|
phone_code_hash=phone_code_hash,
|
||||||
|
@ -279,8 +274,7 @@ async def sign_up(
|
||||||
))
|
))
|
||||||
|
|
||||||
if self._tos:
|
if self._tos:
|
||||||
await self(
|
await self(_tl.fn.help.AcceptTermsOfService(self._tos.id))
|
||||||
_tl.fn.help.AcceptTermsOfService(self._tos.id))
|
|
||||||
|
|
||||||
return await _update_session_state(self, result.user)
|
return await _update_session_state(self, result.user)
|
||||||
|
|
||||||
|
|
|
@ -444,12 +444,10 @@ class TelegramClient:
|
||||||
@forward_call(auth.sign_up)
|
@forward_call(auth.sign_up)
|
||||||
async def sign_up(
|
async def sign_up(
|
||||||
self: 'TelegramClient',
|
self: 'TelegramClient',
|
||||||
code: typing.Union[str, int],
|
|
||||||
first_name: str,
|
first_name: str,
|
||||||
last_name: str = '',
|
last_name: str = '',
|
||||||
*,
|
*,
|
||||||
phone: str = None,
|
code: typing.Union[str, int]) -> '_tl.User':
|
||||||
phone_code_hash: str = None) -> '_tl.User':
|
|
||||||
"""
|
"""
|
||||||
Signs up to Telegram as a new user account.
|
Signs up to Telegram as a new user account.
|
||||||
|
|
||||||
|
@ -463,22 +461,14 @@ class TelegramClient:
|
||||||
and https://core.telegram.org/api/terms.
|
and https://core.telegram.org/api/terms.
|
||||||
|
|
||||||
Arguments
|
Arguments
|
||||||
code (`str` | `int`):
|
|
||||||
The code sent by Telegram
|
|
||||||
|
|
||||||
first_name (`str`):
|
first_name (`str`):
|
||||||
The first name to be used by the new account.
|
The first name to be used by the new account.
|
||||||
|
|
||||||
last_name (`str`, optional)
|
last_name (`str`, optional)
|
||||||
Optional last name.
|
Optional last name.
|
||||||
|
|
||||||
phone (`str` | `int`, optional):
|
code (`str` | `int`):
|
||||||
The phone to sign up. This will be the last phone used by
|
The code sent by Telegram
|
||||||
default (you normally don't need to set this).
|
|
||||||
|
|
||||||
phone_code_hash (`str`, optional):
|
|
||||||
The hash returned by `send_code_request`. This can be left as
|
|
||||||
`None` to use the last hash known for the phone to be used.
|
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
The new created :tl:`User`.
|
The new created :tl:`User`.
|
||||||
|
@ -490,7 +480,7 @@ class TelegramClient:
|
||||||
await client.send_code_request(phone)
|
await client.send_code_request(phone)
|
||||||
|
|
||||||
code = input('enter code: ')
|
code = input('enter code: ')
|
||||||
await client.sign_up(code, first_name='Anna', last_name='Banana')
|
await client.sign_up('Anna', 'Banana', code=code)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@forward_call(auth.send_code_request)
|
@forward_call(auth.send_code_request)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user