Skip to content

Commit b3f647d

Browse files
committed
Add login, logout and attachment endpoint
1 parent 7620c6c commit b3f647d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/main.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from fastapi import FastAPI, Request, Response
1+
from fastapi import HTTPException, FastAPI, Request, Response
22
import os
33
import sqlite3
4+
from os.path import isfile
45

56
app = FastAPI()
67
con = sqlite3.connect(':memory:')
@@ -16,7 +17,7 @@ async def debug_exception_handler(request: Request, exc: Exception):
1617
status_code=500,
1718
content="".join(
1819
traceback.format_exception(
19-
etype=type(exc), value=exc, tb=exc.__traceback__
20+
type(exc), exc, exc.__traceback__
2021
)
2122
)
2223
)
@@ -33,3 +34,22 @@ async def startup_event():
3334
@app.get("/")
3435
async def root():
3536
return {"message": "Hello World"}
37+
38+
@app.get("/login")
39+
async def login(email: str, password: str):
40+
cur = con.cursor()
41+
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))
42+
return cur.fetchone() is not None
43+
44+
@app.get("/logout")
45+
async def root(email: str):
46+
return {"message": "Logged out %s!" % email}
47+
48+
@app.get("/attachment")
49+
async def attachment(attachment_name: str):
50+
attachment_path = 'attachments/' + attachment_name
51+
if not isfile(attachment_path):
52+
raise HTTPException(status_code=404, detail="Attachment not found")
53+
54+
with open(attachment_path) as f:
55+
return f.readlines()

0 commit comments

Comments
 (0)