mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-24 23:09:49 +03:00
sign_in should not send_code_request
This commit is contained in:
parent
6226fa95ce
commit
9bafcdfe0f
|
@ -258,29 +258,22 @@ class AuthMethods(MessageParseMethods, UserMethods):
|
||||||
|
|
||||||
async def sign_in(
|
async def sign_in(
|
||||||
self: 'TelegramClient',
|
self: 'TelegramClient',
|
||||||
phone: str = None,
|
|
||||||
code: typing.Union[str, int] = None,
|
code: typing.Union[str, int] = None,
|
||||||
*,
|
*,
|
||||||
password: str = None,
|
password: str = None,
|
||||||
bot_token: str = None,
|
bot_token: str = None,
|
||||||
|
phone: str = None,
|
||||||
phone_code_hash: str = None) -> 'types.User':
|
phone_code_hash: str = None) -> 'types.User':
|
||||||
"""
|
"""
|
||||||
Logs in to Telegram to an existing user or bot account.
|
Logs in to Telegram to an existing user or bot account.
|
||||||
|
|
||||||
You should only use this if you are not authorized yet.
|
You should only use this if you are not authorized yet.
|
||||||
|
|
||||||
This method will send the code if it's not provided.
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
In most cases, you should simply use `start()` and not this method.
|
In most cases, you should simply use `start()` and not this method.
|
||||||
|
|
||||||
Arguments
|
Arguments
|
||||||
phone (`str` | `int`):
|
|
||||||
The phone to send the code to if no code was provided,
|
|
||||||
or to override the phone that was previously used with
|
|
||||||
these requests.
|
|
||||||
|
|
||||||
code (`str` | `int`):
|
code (`str` | `int`):
|
||||||
The code that Telegram sent. Note that if you have sent this
|
The code that Telegram sent. Note that if you have sent this
|
||||||
code through the application itself it will immediately
|
code through the application itself it will immediately
|
||||||
|
@ -295,30 +288,33 @@ class AuthMethods(MessageParseMethods, UserMethods):
|
||||||
Used to sign in as a bot. Not all requests will be available.
|
Used to sign in as a bot. Not all requests will be available.
|
||||||
This should be the hash the @BotFather gave you.
|
This should be the hash the @BotFather gave you.
|
||||||
|
|
||||||
|
phone (`str` | `int`):
|
||||||
|
By default, the library remembers the phone passed to
|
||||||
|
`send_code_request`. If you are passing the code for
|
||||||
|
a different phone, you should set this parameter.
|
||||||
|
|
||||||
phone_code_hash (`str`, optional):
|
phone_code_hash (`str`, optional):
|
||||||
The hash returned by `send_code_request`. This can be left as
|
By default, the library remembers the hash that
|
||||||
``None`` to use the last hash known for the phone to be used.
|
`send_code_request` returned. If you are passing the
|
||||||
|
code for a different phone, you should set this parameter.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
The signed in user, or the information about
|
The signed in user.
|
||||||
:meth:`send_code_request`.
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
phone = '+34 123 123 123'
|
phone = '+34 123 123 123'
|
||||||
client.sign_in(phone) # send code
|
client.send_code_request(phone)
|
||||||
|
|
||||||
code = input('enter code: ')
|
code = input('enter code: ')
|
||||||
client.sign_in(phone, code)
|
client.sign_in(code)
|
||||||
"""
|
"""
|
||||||
me = await self.get_me()
|
me = await self.get_me()
|
||||||
if me:
|
if me:
|
||||||
return me
|
return me
|
||||||
|
|
||||||
if phone and not code and not password:
|
if code:
|
||||||
return await self.send_code_request(phone)
|
|
||||||
elif code:
|
|
||||||
phone, phone_code_hash = \
|
phone, phone_code_hash = \
|
||||||
self._parse_phone_and_hash(phone, phone_code_hash)
|
self._parse_phone_and_hash(phone, phone_code_hash)
|
||||||
|
|
||||||
|
@ -337,10 +333,7 @@ class AuthMethods(MessageParseMethods, UserMethods):
|
||||||
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 code, password or bot token')
|
||||||
'You must provide a phone and a code the first time, '
|
|
||||||
'and a password only if an RPCError was raised before.'
|
|
||||||
)
|
|
||||||
|
|
||||||
return self._on_login(result.user)
|
return self._on_login(result.user)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user