add whitelists and tokens

This commit is contained in:
Ivanov Matvey 2025-01-24 21:21:42 +10:00
parent c05954deaf
commit 4d54409d7c
7 changed files with 21 additions and 5 deletions

View File

@ -14,7 +14,7 @@ checking_router = APIRouter()
response_model=DeviceProperties response_model=DeviceProperties
) )
async def check_imei(body: CheckingInput): 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") raise AccessDenied("token_is_not_valid")
report: CheckingReport = await Checking_imei_service().request_imei_info(body.imei) report: CheckingReport = await Checking_imei_service().request_imei_info(body.imei)
return report.properties return report.properties

View File

@ -1,5 +1,7 @@
class Authentication_service: class Authentication_service:
@staticmethod @staticmethod
async def token_is_valid(token: str) -> bool: def token_is_valid(token: str) -> bool:
return True with open("tokens.txt") as F:
tokens = F.read().split("\n")
return token in tokens

1
api/tokens.txt Normal file
View File

@ -0,0 +1 @@
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

View File

@ -4,12 +4,15 @@ from aiogram.utils.formatting import Text, Code
from src.dispatcher import dispatcher 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) @dispatcher.message(F.text)
async def ask_imei_info(message: types.Message): 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 raw_imei = message.text
if len(raw_imei) != 15: if len(raw_imei) != 15:
return await message.answer("bad imei - length must be 15") return await message.answer("bad imei - length must be 15")

View File

@ -1 +1,2 @@
from .external_request import External_request_service as External_request_service from .external_request import External_request_service as External_request_service
from .authentication import Authentication_service as Authentication_service

View File

@ -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

1
bot/white_list.txt Normal file
View File

@ -0,0 +1 @@
matv864