mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-18 04:20:57 +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).
|
||||
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.
|
||||
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)
|
||||
|
||||
|
||||
async def sign_up(
|
||||
self: 'TelegramClient',
|
||||
code: typing.Union[str, int],
|
||||
first_name: str,
|
||||
last_name: str = '',
|
||||
*,
|
||||
phone: str = None,
|
||||
phone_code_hash: str = None) -> '_tl.User':
|
||||
me = await self.get_me()
|
||||
if me:
|
||||
return me
|
||||
code: typing.Union[str, int]) -> '_tl.User':
|
||||
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
|
||||
|
||||
# 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.
|
||||
|
@ -259,18 +259,13 @@ async def sign_up(
|
|||
code=code,
|
||||
phone_code_hash=phone_code_hash,
|
||||
)
|
||||
except errors.PhoneNumberUnoccupiedError:
|
||||
except errors.SignUpRequired:
|
||||
pass # code is correct and was used, now need to sign in
|
||||
|
||||
if self._tos and self._tos.text:
|
||||
sys.stderr.write("{}\n".format(self._tos.text))
|
||||
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(
|
||||
phone_number=phone,
|
||||
phone_code_hash=phone_code_hash,
|
||||
|
@ -279,8 +274,7 @@ async def sign_up(
|
|||
))
|
||||
|
||||
if self._tos:
|
||||
await self(
|
||||
_tl.fn.help.AcceptTermsOfService(self._tos.id))
|
||||
await self(_tl.fn.help.AcceptTermsOfService(self._tos.id))
|
||||
|
||||
return await _update_session_state(self, result.user)
|
||||
|
||||
|
|
|
@ -444,12 +444,10 @@ class TelegramClient:
|
|||
@forward_call(auth.sign_up)
|
||||
async def sign_up(
|
||||
self: 'TelegramClient',
|
||||
code: typing.Union[str, int],
|
||||
first_name: str,
|
||||
last_name: str = '',
|
||||
*,
|
||||
phone: str = None,
|
||||
phone_code_hash: str = None) -> '_tl.User':
|
||||
code: typing.Union[str, int]) -> '_tl.User':
|
||||
"""
|
||||
Signs up to Telegram as a new user account.
|
||||
|
||||
|
@ -463,22 +461,14 @@ class TelegramClient:
|
|||
and https://core.telegram.org/api/terms.
|
||||
|
||||
Arguments
|
||||
code (`str` | `int`):
|
||||
The code sent by Telegram
|
||||
|
||||
first_name (`str`):
|
||||
The first name to be used by the new account.
|
||||
|
||||
last_name (`str`, optional)
|
||||
Optional last name.
|
||||
|
||||
phone (`str` | `int`, optional):
|
||||
The phone to sign up. This will be the last phone used by
|
||||
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.
|
||||
code (`str` | `int`):
|
||||
The code sent by Telegram
|
||||
|
||||
Returns
|
||||
The new created :tl:`User`.
|
||||
|
@ -490,7 +480,7 @@ class TelegramClient:
|
|||
await client.send_code_request(phone)
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user