Skip to content

Commit 863be11

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

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main.py

Lines changed: 21 additions & 1 deletion
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:')
@@ -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)