|
|
@ -14,6 +14,9 @@ from app.serializers import * # Import all serializers (detailed in __init__.py)
|
|
|
|
# Import all models (detailed in __init__.py)
|
|
|
|
# Import all models (detailed in __init__.py)
|
|
|
|
from app.models import *
|
|
|
|
from app.models import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Import all DTOs (detailed in __init__.py)
|
|
|
|
|
|
|
|
from app.dto import *
|
|
|
|
|
|
|
|
|
|
|
|
# Contains all constants
|
|
|
|
# Contains all constants
|
|
|
|
from app.config import *
|
|
|
|
from app.config import *
|
|
|
|
|
|
|
|
|
|
|
@ -27,6 +30,12 @@ app = FastAPI()
|
|
|
|
# OAuth2 scheme
|
|
|
|
# OAuth2 scheme
|
|
|
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl=TOKEN_URL)
|
|
|
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl=TOKEN_URL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Collections
|
|
|
|
|
|
|
|
users_collection = db["users"]
|
|
|
|
|
|
|
|
pins_collection = db["pins"]
|
|
|
|
|
|
|
|
friends_collection = db["friends"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Token management
|
|
|
|
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
|
|
|
|
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
|
|
|
|
to_encode = data.copy()
|
|
|
|
to_encode = data.copy()
|
|
|
|
|
|
|
|
|
|
|
@ -62,14 +71,10 @@ async def get_current_user(token: str = Depends(oauth2_scheme)):
|
|
|
|
|
|
|
|
|
|
|
|
return user
|
|
|
|
return user
|
|
|
|
|
|
|
|
|
|
|
|
# Collections
|
|
|
|
|
|
|
|
users_collection = db["users"]
|
|
|
|
|
|
|
|
pins_collection = db["pins"]
|
|
|
|
|
|
|
|
friends_collection = db["friends"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Routes - TODO: find workaround to display 401/409/... HTTP error codes in openapi.json
|
|
|
|
# Routes - TODO: find workaround to display 401/409/... HTTP error codes in openapi.json
|
|
|
|
@app.post("/register", response_model=Token)
|
|
|
|
@app.post("/register", response_model=Token)
|
|
|
|
async def register(user: User):
|
|
|
|
async def register(user: UserRegisterDTO):
|
|
|
|
user_exists = users_collection.find_one({"username": user.username})
|
|
|
|
user_exists = users_collection.find_one({"username": user.username})
|
|
|
|
if user_exists:
|
|
|
|
if user_exists:
|
|
|
|
raise HTTPException(
|
|
|
|
raise HTTPException(
|
|
|
|