Fix login

Remove comment
This commit is contained in:
magmaus3 2022-11-20 19:02:12 +01:00
parent 02d99c0fb1
commit 7e1f86f1c5
Signed by: magmaus3
GPG key ID: 966755D3F4A9B251

View file

@ -34,10 +34,15 @@ async def http_exception_handler(request, exc):
@app.post("/api/v1/login") @app.post("/api/v1/login")
async def login(username: str = Form(), password: str = Form(), version: str = Form()): async def login(username: str = Form(), password: str = Form(), version: str = Form()):
"""User login""" """User login"""
# FIXME Add login
hook.execute_hooks("player_login", username=username) hook.execute_hooks("player_login", username=username)
auth = db.auth_check(username + ":" + password)
return {"token": username + ":" + password, "userId": 1} 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") @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}") @app.get("/api/v1/user/{user_id}")
async def get_user(user_id: int): async def get_user(user_id: int):
"""Returns specified user's profile.""" """Returns specified user's profile."""
# FIXME use database
query = db.user_collection.find_one({"ID": user_id}) query = db.user_collection.find_one({"ID": user_id})
del query["Password"] del query["Password"]
return types.User(**query) return types.User(**query)
@ -198,7 +202,7 @@ async def stopMapPlay(
updateQuery = db.maps_collection.update_one( updateQuery = db.maps_collection.update_one(
{"ID": mapID}, {"ID": mapID},
{"$pull": {"Leaderboard": {"UserID": userData.ID}} {"$pull": {"Leaderboard": {"UserID": userData.ID}},
} }
) )
updateQuery = db.maps_collection.update_one( updateQuery = db.maps_collection.update_one(
@ -283,7 +287,7 @@ async def upload_map(
print(authcheck) print(authcheck)
userData = types.User(**authcheck[1]) userData = types.User(**authcheck[1])
ID = len(list(db.maps_collection.find({}))) + 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( db.maps_collection.insert_one(
{ {
**types.Map( **types.Map(