File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 1- from  fastapi  import  FastAPI , Request , Response 
1+ from  fastapi  import  HTTPException ,  FastAPI , Request , Response 
22import  os 
33import  sqlite3 
4+ from  os .path  import  isfile 
45
56app  =  FastAPI ()
67con  =  sqlite3 .connect (':memory:' )
@@ -33,3 +34,22 @@ async def startup_event():
3334@app .get ("/" ) 
3435async  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 ()
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments