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
2
2
import os
3
3
import sqlite3
4
+ from os .path import isfile
4
5
5
6
app = FastAPI ()
6
7
con = sqlite3 .connect (':memory:' )
@@ -36,12 +37,22 @@ async def root():
36
37
return {"message" : "Hello World" }
37
38
38
39
39
- @app .get ("/login" )
40
+ @app .post ("/login" )
40
41
async def login (email : str , password : str ):
41
42
cur = con .cursor ()
42
43
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 ;
44
46
45
47
@app .get ("/logout" )
46
- async def root (email : str ):
48
+ async def logout (email : str ):
47
49
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