login works backend
This commit is contained in:
@@ -5,14 +5,16 @@ import os
|
||||
import bcrypt
|
||||
import asyncio
|
||||
import logging
|
||||
import uvicorn
|
||||
import copy
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from . import db_setup as db # Import the entire db_setup module
|
||||
from .user_mgmt import *
|
||||
from .media_mgmt import *
|
||||
import db_setup as db # Import the entire db_setup module
|
||||
from user_mgmt import *
|
||||
from media_mgmt import *
|
||||
|
||||
app = FastAPI(
|
||||
title="YT2MP3 API",
|
||||
@@ -39,6 +41,7 @@ async def health_check():
|
||||
@app.get("/me")
|
||||
async def me_endpoint(req: Request):
|
||||
query = dict(req.query_params)
|
||||
print(query)
|
||||
if "id" not in query.keys(): raise HTTPException(400, "Give ID")
|
||||
|
||||
user = await fetch_user_info(query["id"],"id")
|
||||
@@ -54,7 +57,7 @@ async def login_endpoint(req: Request):
|
||||
if body.get(key) is None:
|
||||
raise HTTPException(400, "Missing args")
|
||||
|
||||
login_obj = login_user(body["email"], body["password"])
|
||||
login_obj = await login_user(body["email"], body["password"])
|
||||
if login_obj is None:
|
||||
raise HTTPException(401, "Incorrect login")
|
||||
else:
|
||||
@@ -72,19 +75,20 @@ async def register_endpoint(req: Request):
|
||||
if await fetch_user_info(body["email"],"email") is not None:
|
||||
raise HTTPException(403, "User already exists")
|
||||
|
||||
create_user(body["fist_name"], body["last_name"], body["email"], body["password"])
|
||||
await create_user(body["first_name"], body["last_name"], body["email"], body["password"])
|
||||
return PlainTextResponse("User registered")
|
||||
|
||||
@app.put("/edit_user")
|
||||
async def edit_endpoint(req: Request):
|
||||
body:dict = await req.json()
|
||||
print(body.keys())
|
||||
|
||||
if "user_id" not in body.keys(): raise HTTPException(400, "Provide user ID")
|
||||
|
||||
params = body
|
||||
params = copy.deepcopy(body) # to create a completely new version (ridiculous but okay)
|
||||
params.pop("user_id")
|
||||
|
||||
edit_user(body["user_id"], params)
|
||||
await edit_user(body["user_id"], params)
|
||||
return PlainTextResponse("User edited")
|
||||
|
||||
#
|
||||
@@ -121,4 +125,10 @@ async def begin_conversion(req: Request):
|
||||
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to download video")
|
||||
except Exception as e:
|
||||
logger.exception(f"Error during media conversion: {e}")
|
||||
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to convert media")
|
||||
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to convert media")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
listen_host = str(os.environ.get("HOST", "127.0.0.1"))
|
||||
listen_port = int(os.environ.get("PORT", 3000))
|
||||
uvicorn.run(app,host=listen_host,port=listen_port)
|
||||
Reference in New Issue
Block a user