File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 1- from fastapi import FastAPI , Request , Response
1+ from fastapi import FastAPI , Request , Response , HTTPException
22import os
33import sqlite3
4+ from os .path import isfile
45
56app = FastAPI ()
67con = sqlite3 .connect (':memory:' )
@@ -36,12 +37,22 @@ async def root():
3637 return {"message" : "Hello World" }
3738
3839
39- @app .get ("/login" )
40+ @app .post ("/login" )
4041async def login (email : str , password : str ):
4142 cur = con .cursor ()
4243 cur .execute ("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email , password ))
43- return cur .fetchone () is not None
44+ if cur .fetchone ():
45+ return email ;
4446
4547@app .get ("/logout" )
46- async def root (email : str ):
48+ async def logout (email : str ):
4749 return {"message" : "Logged out %s!" % email }
50+
51+ @app .get ("/attachment" )
52+ async def attachment (attachment_name : str ):
53+ attachment_path = 'attachments/' + attachment_name
54+ if not isfile (attachment_path ):
55+ raise HTTPException (status_code = 404 , detail = "Attachment not found" )
56+
57+ with open (attachment_path ) as f :
58+ return f .readlines ()
You can’t perform that action at this time.
0 commit comments