Update files
This commit is contained in:
parent
3074fc7566
commit
d278329ba6
|
|
@ -60,6 +60,59 @@ async def on_disconnect_root(sid):
|
|||
print(f"[WebSocket] Client disconnected from ROOT namespace: {sid}")
|
||||
logger.info(f"[WebSocket] Client disconnected from ROOT namespace: {sid}")
|
||||
|
||||
# Обработчик auth в корневом namespace - обрабатываем так же, как в /mod-chat
|
||||
@sio.on('auth')
|
||||
async def on_auth_root(sid, data):
|
||||
"""Handle auth in root namespace - process same as /mod-chat"""
|
||||
print(f"[WebSocket] 📥 Auth запрос в ROOT namespace от {sid}: {data}")
|
||||
print(f"[WebSocket] ⚠️ Клиент авторизуется в корневом namespace, обрабатываем здесь")
|
||||
|
||||
try:
|
||||
username = normalize_username(data.get('username')) if data.get('username') else None
|
||||
telegram_id = data.get('telegramId')
|
||||
|
||||
print(f"[WebSocket] Обработка auth в ROOT: username={username}, telegramId={telegram_id}")
|
||||
|
||||
if not username or not telegram_id:
|
||||
print(f"[WebSocket] ❌ Auth failed: missing username or telegramId")
|
||||
await sio.emit('unauthorized', room=sid)
|
||||
await sio.disconnect(sid)
|
||||
return
|
||||
|
||||
# Check if user is owner
|
||||
owner_usernames = settings.OWNER_USERNAMES_LIST
|
||||
is_owner = username.lower() in [u.lower() for u in owner_usernames]
|
||||
|
||||
# Check if user is moderation admin
|
||||
admin = await moderation_admins_collection().find_one({
|
||||
'telegramId': str(telegram_id)
|
||||
})
|
||||
is_admin = admin is not None
|
||||
|
||||
if not is_owner and not is_admin:
|
||||
print(f"[WebSocket] ❌ Access denied: {username} (telegramId: {telegram_id})")
|
||||
await sio.emit('unauthorized', room=sid)
|
||||
await sio.disconnect(sid)
|
||||
return
|
||||
|
||||
# Store connection data (используем тот же словарь, что и для /mod-chat)
|
||||
connected_moderators[sid] = {
|
||||
'username': username,
|
||||
'telegramId': telegram_id,
|
||||
'isOwner': is_owner
|
||||
}
|
||||
|
||||
print(f"[WebSocket] ✅ Auth success в ROOT namespace: {username} (owner: {is_owner}, admin: {is_admin})")
|
||||
await sio.emit('ready', room=sid)
|
||||
broadcast_online()
|
||||
|
||||
except Exception as e:
|
||||
print(f"[WebSocket] ❌ Error in auth (ROOT): {type(e).__name__}: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
await sio.emit('unauthorized', room=sid)
|
||||
await sio.disconnect(sid)
|
||||
|
||||
# Namespace handlers for /mod-chat
|
||||
@sio.on('connect', namespace='/mod-chat')
|
||||
async def on_connect(sid, environ):
|
||||
|
|
|
|||
Loading…
Reference in New Issue