From 7e1f86f1c555f18e725cabe280e41933599a4932 Mon Sep 17 00:00:00 2001 From: magmaus3 Date: Sun, 20 Nov 2022 19:02:12 +0100 Subject: [PATCH] Fix login Remove comment --- customiwmserver/main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/customiwmserver/main.py b/customiwmserver/main.py index 0614f02..395e431 100644 --- a/customiwmserver/main.py +++ b/customiwmserver/main.py @@ -34,10 +34,15 @@ async def http_exception_handler(request, exc): @app.post("/api/v1/login") async def login(username: str = Form(), password: str = Form(), version: str = Form()): """User login""" - # FIXME Add login hook.execute_hooks("player_login", username=username) - - return {"token": username + ":" + password, "userId": 1} + auth = db.auth_check(username + ":" + password) + if not auth[0]: + if auth[1] == "nouser": + raise HTTPException(404, detail="User not found.") + elif auth[1] == "wrongpass": + raise HTTPException(403, detail="Password is incorrect.") + else: + return {"token": username + ":" + password, "userId": auth[1]["ID"]} @app.put("/api/v1/user") @@ -79,7 +84,6 @@ async def refresh_login(Authorization: Union[str, None] = Header(default=None)): @app.get("/api/v1/user/{user_id}") async def get_user(user_id: int): """Returns specified user's profile.""" - # FIXME use database query = db.user_collection.find_one({"ID": user_id}) del query["Password"] return types.User(**query) @@ -198,7 +202,7 @@ async def stopMapPlay( updateQuery = db.maps_collection.update_one( {"ID": mapID}, - {"$pull": {"Leaderboard": {"UserID": userData.ID}} + {"$pull": {"Leaderboard": {"UserID": userData.ID}}, } ) updateQuery = db.maps_collection.update_one( @@ -283,7 +287,7 @@ async def upload_map( print(authcheck) userData = types.User(**authcheck[1]) ID = len(list(db.maps_collection.find({}))) + 1 - MapCode = db.id_to_mapcode(ID) # FIXME Add mapcodes correctly + MapCode = db.id_to_mapcode(ID) db.maps_collection.insert_one( { **types.Map(