Skip to content

Commit

Permalink
Add login, logout and attachment endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vlussenburg committed Jan 12, 2023
1 parent 7620c6c commit 863be11
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import FastAPI, Request, Response
from fastapi import HTTPException, FastAPI, Request, Response
import os
import sqlite3
from os.path import isfile

app = FastAPI()
con = sqlite3.connect(':memory:')
Expand Down Expand Up @@ -33,3 +34,22 @@ async def startup_event():
@app.get("/")
async def root():
return {"message": "Hello World"}

@app.get("/login")
async def login(email: str, password: str):
cur = con.cursor()
cur.execute("SELECT * FROM users WHERE email = '%s' and password = '%s'" % (email, password))
return cur.fetchone() is not None

@app.get("/logout")
async def root(email: str):
return {"message": "Logged out %s!" % email}

@app.get("/attachment")
async def attachment(attachment_name: str):
attachment_path = 'attachments/' + attachment_name
if not isfile(attachment_path):
raise HTTPException(status_code=404, detail="Attachment not found")

with open(attachment_path) as f:
return f.readlines()

0 comments on commit 863be11

Please sign in to comment.