diff --git a/src/main.py b/src/main.py index 3b292e6..ce0a30f 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,7 @@ -from fastapi import FastAPI, Request, Response +from fastapi import HTTPException, FastAPI, Request, Response import os import sqlite3 +from os.path import isfile app = FastAPI() con = sqlite3.connect(':memory:') @@ -16,7 +17,7 @@ async def debug_exception_handler(request: Request, exc: Exception): status_code=500, content="".join( traceback.format_exception( - etype=type(exc), value=exc, tb=exc.__traceback__ + type(exc), exc, exc.__traceback__ ) ) ) @@ -34,3 +35,21 @@ async def startup_event(): async def root(): return {"message": "Hello World"} +@app.get("/login") +async def login(email: str, password: str): + cur = con.cursor() + cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password)) + return cur.fetchone() is not None + +@app.get("/logout") +async def root(email: str): + return {"message": "Logged out %s!" % email} + +@app.get("/attachment") +async def attachment(attachment_name: str): + attachment_path = 'attachments/' + attachment_name + if not isfile(attachment_path): + raise HTTPException(status_code=404, detail="Attachment not found") + + with open(attachment_path) as f: + return f.readlines() \ No newline at end of file