Изменения мидлваре
This commit is contained in:
parent
f77297f23b
commit
51f32c0750
2 changed files with 8 additions and 6 deletions
|
@ -9,7 +9,7 @@ from app.unit_of_work import UnitOfWork
|
||||||
from app.utils.auth import AuthService
|
from app.utils.auth import AuthService
|
||||||
from app.chat.router import router
|
from app.chat.router import router
|
||||||
from app.chat.shemas import SSendMessage, SMessage, SDeleteMessage, SEditMessage, SPinMessage, SUnpinMessage
|
from app.chat.shemas import SSendMessage, SMessage, SDeleteMessage, SEditMessage, SPinMessage, SUnpinMessage
|
||||||
from app.users.dependencies import get_current_user_ws, get_token, get_subprotocol
|
from app.users.dependencies import get_current_user_ws, get_token, get_subprotocol_ws
|
||||||
from app.users.schemas import SUser
|
from app.users.schemas import SUser
|
||||||
|
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ async def websocket_endpoint(
|
||||||
chat_id: int,
|
chat_id: int,
|
||||||
websocket: WebSocket,
|
websocket: WebSocket,
|
||||||
user: SUser = Depends(get_current_user_ws),
|
user: SUser = Depends(get_current_user_ws),
|
||||||
subprotocol: str = Depends(get_subprotocol),
|
subprotocol: str = Depends(get_subprotocol_ws),
|
||||||
uow=Depends(UnitOfWork),
|
uow=Depends(UnitOfWork),
|
||||||
):
|
):
|
||||||
await AuthService.check_verificated_user_with_exc(uow=uow, user_id=user.id)
|
await AuthService.check_verificated_user_with_exc(uow=uow, user_id=user.id)
|
||||||
|
|
|
@ -54,8 +54,7 @@ async def check_verificated_user_with_exc(user: SUser = Depends(get_current_user
|
||||||
def get_token_ws(sec_websocket_protocol: Annotated[str | None, Header()] = None) -> str:
|
def get_token_ws(sec_websocket_protocol: Annotated[str | None, Header()] = None) -> str:
|
||||||
if sec_websocket_protocol is None:
|
if sec_websocket_protocol is None:
|
||||||
raise TokenAbsentException
|
raise TokenAbsentException
|
||||||
logging.critical(sec_websocket_protocol)
|
return sec_websocket_protocol.split()[-1]
|
||||||
return sec_websocket_protocol
|
|
||||||
|
|
||||||
|
|
||||||
async def get_current_user_ws(token: str = Depends(get_token_ws), uow=Depends(UnitOfWork)):
|
async def get_current_user_ws(token: str = Depends(get_token_ws), uow=Depends(UnitOfWork)):
|
||||||
|
@ -76,5 +75,8 @@ async def get_current_user_ws(token: str = Depends(get_token_ws), uow=Depends(Un
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
async def get_subprotocol():
|
|
||||||
pass
|
async def get_subprotocol_ws(sec_websocket_protocol: Annotated[str | None, Header()] = None) -> str:
|
||||||
|
if sec_websocket_protocol is None:
|
||||||
|
raise TokenAbsentException
|
||||||
|
return sec_websocket_protocol.split(",")[0]
|
||||||
|
|
Loading…
Add table
Reference in a new issue