add whitelists and tokens
This commit is contained in:
parent
c05954deaf
commit
4d54409d7c
@ -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
|
@ -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
|
||||
|
1
api/tokens.txt
Normal file
1
api/tokens.txt
Normal file
@ -0,0 +1 @@
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
@ -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")
|
||||
|
@ -1 +1,2 @@
|
||||
from .external_request import External_request_service as External_request_service
|
||||
from .authentication import Authentication_service as Authentication_service
|
||||
|
8
bot/src/services/authentication.py
Normal file
8
bot/src/services/authentication.py
Normal 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
1
bot/white_list.txt
Normal file
@ -0,0 +1 @@
|
||||
matv864
|
Loading…
x
Reference in New Issue
Block a user