39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
from config import config
|
||
import re
|
||
|
||
|
||
ALLOWED_PHONE_NUMBERS = list(config.get("users", {}).keys())
|
||
|
||
AUTHORIZED_USERS = {}
|
||
|
||
|
||
def check_user_auth(phone: str) -> bool:
|
||
return phone in ALLOWED_PHONE_NUMBERS
|
||
|
||
|
||
def normalize_phone(phone: str) -> str:
|
||
phone = phone.strip()
|
||
phone = re.sub(r"[^\d+]", "", phone)
|
||
if not phone.startswith("+"):
|
||
phone = "+" + phone
|
||
return phone
|
||
|
||
|
||
def authorize_user(user_id: int, phone: str) -> bool:
|
||
normalized_phone = normalize_phone(phone)
|
||
if normalized_phone in ALLOWED_PHONE_NUMBERS:
|
||
AUTHORIZED_USERS[user_id] = normalized_phone
|
||
# if check_user_auth(phone):
|
||
# AUTHORIZED_USERS[user_id] = phone
|
||
print(f"{user_id} авторизован с номером: {normalized_phone}")
|
||
return True
|
||
else:
|
||
print(
|
||
f"Пользователь {user_id} пытался авторизоваться с номером {normalized_phone}"
|
||
)
|
||
return False
|
||
|
||
|
||
def is_user_auth(user_id: int) -> bool:
|
||
return user_id in AUTHORIZED_USERS
|