Skip to content

Commit

Permalink
Add login endpoint
Browse files Browse the repository at this point in the history
Add logout endpoint
Add attachment endpoint
  • Loading branch information
vlussenburg committed Jan 12, 2023
1 parent 413b928 commit 0c8cfbb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/mapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
<<<<<<< HEAD
uses: actions/checkout@v3
=======
uses: actions/checkout@v2
>>>>>>> c71c25e (Update mapi.yml)

# Create environment to run API
- name: Set up Python
Expand Down
24 changes: 23 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
import os
import sqlite3
from os.path import isfile

app = FastAPI()
con = sqlite3.connect(':memory:')
Expand All @@ -19,7 +20,7 @@ async def debug_exception_handler(request: Request, exc: Exception):
etype=type(exc), value=exc, tb=exc.__traceback__
)
)
)
)

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


@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 0c8cfbb

Please sign in to comment.