From d3e63fbae93792f2663a4a1dd5a85f0ab2cb94c3 Mon Sep 17 00:00:00 2001 From: Colin Bassett Date: Tue, 25 Feb 2025 12:04:04 -0500 Subject: [PATCH] Implement a working login function --- api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api.py b/api.py index 0b08dd3..271e2b8 100644 --- a/api.py +++ b/api.py @@ -1,8 +1,6 @@ # Imports from contextlib import asynccontextmanager - from fastapi import FastAPI, HTTPException - from functions import * @@ -25,6 +23,7 @@ def create_hero(hero: HeroCreate, session: SessionDep): session.refresh(db_hero) return db_hero + @app.get("/heroes/{id}", response_model=Hero) def get_hero(id: int, session: SessionDep): hero = session.get(Hero, id) @@ -59,10 +58,12 @@ def delete_hero(id: int, session: SessionDep): @app.post("/verify") def verify_user(email: str, password: str, session: SessionDep): user = get_hero_by_email(email, session) + if not user: + return {"message": "Authentication failed", "continue": False} # check if the password is correct authenticate_user = verify_password(password, user.hash, user.salt) if authenticate_user: return {"message": "Authentication successful", "continue": True} - return {"message": "Authentication failed", "continue": False} \ No newline at end of file + return {"message": "Authentication failed", "continue": False}