При получении куки она обновляется
This commit is contained in:
parent
0dffe1097f
commit
760db3d819
3 changed files with 9 additions and 6 deletions
|
@ -15,7 +15,7 @@ router = APIRouter(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get('')
|
@router.get("")
|
||||||
async def get_all_chats(user: Users = Depends(get_current_user)):
|
async def get_all_chats(user: Users = Depends(get_current_user)):
|
||||||
return await UserDAO.get_user_allowed_chats(user.id)
|
return await UserDAO.get_user_allowed_chats(user.id)
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ async def get_last_message(chat_id: int, user: Users = Depends(get_current_user)
|
||||||
if message is None:
|
if message is None:
|
||||||
raise MessageNotFoundException
|
raise MessageNotFoundException
|
||||||
for mes in message:
|
for mes in message:
|
||||||
mes['created_at'] = mes['created_at'].isoformat()
|
mes["created_at"] = mes["created_at"].isoformat()
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,5 +89,5 @@ async def get_some_messages(
|
||||||
if not messages:
|
if not messages:
|
||||||
raise MessageNotFoundException
|
raise MessageNotFoundException
|
||||||
for mes in messages:
|
for mes in messages:
|
||||||
mes['created_at'] = mes['created_at'].isoformat()
|
mes["created_at"] = mes["created_at"].isoformat()
|
||||||
return messages
|
return messages
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from fastapi import Depends, Request
|
from fastapi import Depends, Request, Response
|
||||||
from jose import JWTError, jwt
|
from jose import JWTError, jwt
|
||||||
|
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
from app.exceptions import (IncorrectTokenFormatException,
|
from app.exceptions import (IncorrectTokenFormatException,
|
||||||
TokenAbsentException, TokenExpiredException,
|
TokenAbsentException, TokenExpiredException,
|
||||||
UserIsNotPresentException)
|
UserIsNotPresentException)
|
||||||
|
from app.users.auth import create_access_token
|
||||||
from app.users.dao import UserDAO
|
from app.users.dao import UserDAO
|
||||||
from app.users.models import Users
|
from app.users.models import Users
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ def get_token(request: Request):
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
async def get_current_user(token: str = Depends(get_token)) -> Users:
|
async def get_current_user(response: Response, token: str = Depends(get_token)) -> Users:
|
||||||
try:
|
try:
|
||||||
payload = jwt.decode(
|
payload = jwt.decode(
|
||||||
token, settings.SECRET_KEY, settings.ALGORITHM
|
token, settings.SECRET_KEY, settings.ALGORITHM
|
||||||
|
@ -34,6 +35,8 @@ async def get_current_user(token: str = Depends(get_token)) -> Users:
|
||||||
user = await UserDAO.find_one_or_none(id=int(user_id))
|
user = await UserDAO.find_one_or_none(id=int(user_id))
|
||||||
if not user:
|
if not user:
|
||||||
raise UserIsNotPresentException
|
raise UserIsNotPresentException
|
||||||
|
access_token = create_access_token({"sub": str(user.id)})
|
||||||
|
response.set_cookie(key="black_phoenix_access_token", value=access_token, httponly=True)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from app.config import settings
|
||||||
from app.exceptions import UserAlreadyExistsException, UsernameAlreadyInUseException, \
|
from app.exceptions import UserAlreadyExistsException, UsernameAlreadyInUseException, \
|
||||||
IncorrectPasswordException, PasswordsМismatchException, WrongCodeException, UserNotFoundException
|
IncorrectPasswordException, PasswordsМismatchException, WrongCodeException, UserNotFoundException
|
||||||
from app.images.router import upload_file, upload_file_returning_str
|
from app.images.router import upload_file, upload_file_returning_str
|
||||||
from app.users.auth import get_password_hash, authenticate_user_by_email, authenticate_user_by_username, \
|
from app.users.auth import get_password_hash, authenticate_user_by_email, \
|
||||||
create_access_token, verify_password, REGISTRATED_USER, get_user_codes_list, VERIFICATED_USER, authenticate_user, \
|
create_access_token, verify_password, REGISTRATED_USER, get_user_codes_list, VERIFICATED_USER, authenticate_user, \
|
||||||
check_existing_user
|
check_existing_user
|
||||||
from app.users.dao import UserDAO, UserCodesDAO
|
from app.users.dao import UserDAO, UserCodesDAO
|
||||||
|
|
Loading…
Add table
Reference in a new issue