Исправление админки: сессия по паролю (можно отменять записи после /admin <пароль>)

This commit is contained in:
devproject
2026-06-14 22:05:38 +04:00
parent c1f06d299e
commit 0791a096a8
+10 -6
View File
@@ -3,17 +3,24 @@ from aiogram import Router, F
from aiogram.types import Message, CallbackQuery from aiogram.types import Message, CallbackQuery
from aiogram.filters import Command, CommandObject from aiogram.filters import Command, CommandObject
from app.db.memory import load_bookings from app.db.memory import load_bookings
from app.config import ADMIN_IDS, ADMIN_PASSWORD from app.config import ADMIN_PASSWORD
from app.logger import logger from app.logger import logger
router = Router() router = Router()
ADMIN_IDS = {991309145}
# Store approved sessions — user_ids that passed password check
_approved = set()
def is_admin(user_id: int, password: str | None = None) -> bool: def is_admin(user_id: int, password: str | None = None) -> bool:
"""Check if user is admin: by user_id or by password.""" """Check if user is admin: by user_id, by password, or by approved session."""
if user_id in ADMIN_IDS: if user_id in ADMIN_IDS:
return True return True
if user_id in _approved:
return True
if password and password == ADMIN_PASSWORD: if password and password == ADMIN_PASSWORD:
_approved.add(user_id)
return True return True
return False return False
@@ -21,13 +28,10 @@ def is_admin(user_id: int, password: str | None = None) -> bool:
@router.message(Command("admin")) @router.message(Command("admin"))
async def admin_panel(message: Message, command: CommandObject): async def admin_panel(message: Message, command: CommandObject):
uid = message.from_user.id uid = message.from_user.id
# Get password from command args
password = command.args password = command.args
if not is_admin(uid, password=password): if not is_admin(uid, password=password):
# Silent — no hint about how to get in return # Silent
return
logger.info("Admin {uid} opened admin panel", uid=uid) logger.info("Admin {uid} opened admin panel", uid=uid)