Skip to content

Commit f9014dd

Browse files
committed
Add login, logout and attachment endpoint
1 parent 413b928 commit f9014dd

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/main.py

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

56
app = FastAPI()
67
con = sqlite3.connect(':memory:')
@@ -19,7 +20,7 @@ async def debug_exception_handler(request: Request, exc: Exception):
1920
etype=type(exc), value=exc, tb=exc.__traceback__
2021
)
2122
)
22-
)
23+
)
2324

2425
@app.on_event("startup")
2526
async def startup_event():
@@ -29,7 +30,28 @@ async def startup_event():
2930
cur.execute('''CREATE TABLE users (email text, password text)''')
3031
cur.execute('''INSERT INTO users VALUES ('[email protected]', '123456')''')
3132
con.commit()
33+
3234

3335
@app.get("/")
3436
async def root():
3537
return {"message": "Hello World"}
38+
39+
40+
@app.get("/login")
41+
async def login(email: str, password: str):
42+
cur = con.cursor()
43+
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))
44+
return cur.fetchone() is not None
45+
46+
@app.get("/logout")
47+
async def root(email: str):
48+
return {"message": "Logged out %s!" % email}
49+
50+
@app.get("/attachment")
51+
async def attachment(attachment_name: str):
52+
attachment_path = 'attachments/' + attachment_name
53+
if not isfile(attachment_path):
54+
raise HTTPException(status_code=404, detail="Attachment not found")
55+
56+
with open(attachment_path) as f:
57+
return f.readlines()

0 commit comments

Comments
 (0)