diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index dcd12cf1..f335558e 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -423,12 +423,10 @@ def pyrogram_api(): sign_in sign_in_bot sign_in_qrcode - sign_up get_password_hint check_password send_recovery_code recover_password - accept_terms_of_service log_out get_active_sessions """, diff --git a/pyrogram/client.py b/pyrogram/client.py index b467042a..4cb1f994 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -52,7 +52,7 @@ from pyrogram.handlers.handler import Handler from pyrogram.methods import Methods from pyrogram.session import Auth, Session from pyrogram.storage import FileStorage, MemoryStorage, Storage -from pyrogram.types import User, TermsOfService +from pyrogram.types import User from pyrogram.utils import ainput from .connection import Connection from .connection.transport import TCPAbridged @@ -523,28 +523,6 @@ class Client(Methods): if isinstance(signed_in, User): return signed_in - while True: - first_name = await ainput("Enter first name: ") - last_name = await ainput("Enter last name (empty to skip): ") - - try: - signed_up = await self.sign_up( - self.phone_number, - sent_code.phone_code_hash, - first_name, - last_name - ) - except BadRequest as e: - print(e.MESSAGE) - else: - break - - if isinstance(signed_in, TermsOfService): - print("\n" + signed_in.text + "\n") - await self.accept_terms_of_service(signed_in.id) - - return signed_up - def set_parse_mode(self, parse_mode: Optional["enums.ParseMode"]): """Set the parse mode to be used globally by the client. diff --git a/pyrogram/methods/auth/__init__.py b/pyrogram/methods/auth/__init__.py index d5cab5c1..3735bf9a 100644 --- a/pyrogram/methods/auth/__init__.py +++ b/pyrogram/methods/auth/__init__.py @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . -from .accept_terms_of_service import AcceptTermsOfService from .check_password import CheckPassword from .connect import Connect from .disconnect import Disconnect @@ -32,12 +31,10 @@ from .send_recovery_code import SendRecoveryCode from .sign_in import SignIn from .sign_in_bot import SignInBot from .sign_in_qrcode import SignInQrcode -from .sign_up import SignUp from .terminate import Terminate class Auth( - AcceptTermsOfService, CheckPassword, Connect, Disconnect, @@ -52,7 +49,6 @@ class Auth( SignIn, SignInBot, SignInQrcode, - SignUp, Terminate ): pass diff --git a/pyrogram/methods/auth/accept_terms_of_service.py b/pyrogram/methods/auth/accept_terms_of_service.py deleted file mode 100644 index fa94fbc0..00000000 --- a/pyrogram/methods/auth/accept_terms_of_service.py +++ /dev/null @@ -1,45 +0,0 @@ -# Pyrofork - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-present Dan -# Copyright (C) 2022-present Mayuri-Chan -# -# This file is part of Pyrofork. -# -# Pyrofork is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pyrofork is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with Pyrofork. If not, see . - -import pyrogram -from pyrogram import raw - - -class AcceptTermsOfService: - async def accept_terms_of_service( - self: "pyrogram.Client", - terms_of_service_id: str - ) -> bool: - """Accept the given terms of service. - - .. include:: /_includes/usable-by/users.rst - - Parameters: - terms_of_service_id (``str``): - The terms of service identifier. - """ - r = await self.invoke( - raw.functions.help.AcceptTermsOfService( - id=raw.types.DataJSON( - data=terms_of_service_id - ) - ) - ) - - return bool(r) diff --git a/pyrogram/methods/auth/sign_in.py b/pyrogram/methods/auth/sign_in.py index 90498aed..35af26f6 100644 --- a/pyrogram/methods/auth/sign_in.py +++ b/pyrogram/methods/auth/sign_in.py @@ -23,6 +23,7 @@ from typing import Union import pyrogram from pyrogram import raw from pyrogram import types +from pyrogram.errors import PhoneNumberUnoccupied log = logging.getLogger(__name__) @@ -49,15 +50,13 @@ class SignIn: The valid confirmation code you received (either as Telegram message or as SMS in your phone number). Returns: - :obj:`~pyrogram.types.User` | :obj:`~pyrogram.types.TermsOfService` | bool: On success, in case the - authorization completed, the user is returned. In case the phone number needs to be registered first AND the - terms of services accepted (with :meth:`~pyrogram.Client.accept_terms_of_service`), an object containing - them is returned. In case the phone number needs to be registered, but the terms of services don't need to - be accepted, False is returned instead. + :obj:`~pyrogram.types.User` | bool: On success, in case the + authorization completed, the user is returned. Raises: BadRequest: In case the arguments are invalid. SessionPasswordNeeded: In case a password is needed to sign in. + PhoneNumberUnoccupied: In case the phone number is not registered on Telegram. """ phone_number = phone_number.strip(" +") @@ -70,10 +69,7 @@ class SignIn: ) if isinstance(r, raw.types.auth.AuthorizationSignUpRequired): - if r.terms_of_service: - return types.TermsOfService._parse(terms_of_service=r.terms_of_service) - - return False + raise PhoneNumberUnoccupied("The phone number is not registered on Telegram. Please use official Telegram app to register it.") else: await self.storage.user_id(r.user.id) await self.storage.is_bot(False) diff --git a/pyrogram/methods/auth/sign_up.py b/pyrogram/methods/auth/sign_up.py deleted file mode 100644 index c1eef80f..00000000 --- a/pyrogram/methods/auth/sign_up.py +++ /dev/null @@ -1,74 +0,0 @@ -# Pyrofork - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-present Dan -# Copyright (C) 2022-present Mayuri-Chan -# -# This file is part of Pyrofork. -# -# Pyrofork is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pyrofork is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with Pyrofork. If not, see . - -import logging - -import pyrogram -from pyrogram import raw -from pyrogram import types - -log = logging.getLogger(__name__) - - -class SignUp: - async def sign_up( - self: "pyrogram.Client", - phone_number: str, - phone_code_hash: str, - first_name: str, - last_name: str = "" - ) -> "types.User": - """Register a new user in Telegram. - - .. include:: /_includes/usable-by/users.rst - - Parameters: - phone_number (``str``): - Phone number in international format (includes the country prefix). - - phone_code_hash (``str``): - Code identifier taken from the result of :meth:`~pyrogram.Client.send_code`. - - first_name (``str``): - New user first name. - - last_name (``str``, *optional*): - New user last name. Defaults to "" (empty string, no last name). - - Returns: - :obj:`~pyrogram.types.User`: On success, the new registered user is returned. - - Raises: - BadRequest: In case the arguments are invalid. - """ - phone_number = phone_number.strip(" +") - - r = await self.invoke( - raw.functions.auth.SignUp( - phone_number=phone_number, - first_name=first_name, - last_name=last_name, - phone_code_hash=phone_code_hash - ) - ) - - await self.storage.user_id(r.user.id) - await self.storage.is_bot(False) - - return types.User._parse(self, r.user)