diff --git a/api/src/api/check_imei.py b/api/src/api/check_imei.py index be231eb..acbf0d4 100644 --- a/api/src/api/check_imei.py +++ b/api/src/api/check_imei.py @@ -14,7 +14,7 @@ checking_router = APIRouter() response_model=DeviceProperties ) async def check_imei(body: CheckingInput): - if not await Authentication_service.token_is_valid(token=body.token): + if not Authentication_service.token_is_valid(token=body.token): raise AccessDenied("token_is_not_valid") report: CheckingReport = await Checking_imei_service().request_imei_info(body.imei) return report.properties \ No newline at end of file diff --git a/api/src/service/authentication.py b/api/src/service/authentication.py index 91a1713..f37403e 100644 --- a/api/src/service/authentication.py +++ b/api/src/service/authentication.py @@ -1,5 +1,7 @@ class Authentication_service: @staticmethod - async def token_is_valid(token: str) -> bool: - return True + def token_is_valid(token: str) -> bool: + with open("tokens.txt") as F: + tokens = F.read().split("\n") + return token in tokens diff --git a/api/tokens.txt b/api/tokens.txt new file mode 100644 index 0000000..293ce40 --- /dev/null +++ b/api/tokens.txt @@ -0,0 +1 @@ +e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 \ No newline at end of file diff --git a/bot/src/handlers/ask_imei.py b/bot/src/handlers/ask_imei.py index eb4528f..9c62263 100644 --- a/bot/src/handlers/ask_imei.py +++ b/bot/src/handlers/ask_imei.py @@ -4,12 +4,15 @@ from aiogram.utils.formatting import Text, Code from src.dispatcher import dispatcher -from src.services import External_request_service +from src.services import External_request_service, Authentication_service @dispatcher.message(F.text) async def ask_imei_info(message: types.Message): + if not Authentication_service.user_in_white_list(message.from_user.username): + return await message.answer("you aren't in white list") + raw_imei = message.text if len(raw_imei) != 15: return await message.answer("bad imei - length must be 15") diff --git a/bot/src/services/__init__.py b/bot/src/services/__init__.py index e226325..bbbc22f 100644 --- a/bot/src/services/__init__.py +++ b/bot/src/services/__init__.py @@ -1 +1,2 @@ -from .external_request import External_request_service as External_request_service \ No newline at end of file +from .external_request import External_request_service as External_request_service +from .authentication import Authentication_service as Authentication_service diff --git a/bot/src/services/authentication.py b/bot/src/services/authentication.py new file mode 100644 index 0000000..7254333 --- /dev/null +++ b/bot/src/services/authentication.py @@ -0,0 +1,8 @@ +class Authentication_service: + + @staticmethod + def user_in_white_list(username: str) -> bool: + with open("white_list.txt") as F: + usernames = F.read().split("\n") + + return username in usernames diff --git a/bot/white_list.txt b/bot/white_list.txt new file mode 100644 index 0000000..e56d20f --- /dev/null +++ b/bot/white_list.txt @@ -0,0 +1 @@ +matv864 \ No newline at end of file