1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Создание чата9testt

This commit is contained in:
MoonTestUse1
2025-01-05 06:32:34 +06:00
parent 9ba671bdaa
commit 7f7838a0d3
28 changed files with 653 additions and 721 deletions

View File

@@ -62,31 +62,4 @@ async def get_current_user(
user = db.query(User).filter(User.email == email).first()
if user is None:
raise credentials_exception
return user
async def get_current_user_ws(websocket: WebSocket, db: Session = Depends(get_db)) -> Optional[User]:
try:
# Получаем токен из параметров запроса
token = websocket.query_params.get("token")
if not token:
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
return None
# Проверяем токен
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
email: str = payload.get("sub")
if email is None:
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
return None
# Получаем пользователя
user = db.query(User).filter(User.email == email).first()
if user is None:
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
return None
return user
except JWTError:
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
return None
return user