-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logout endpoint Add attachment endpoint
- Loading branch information
1 parent
413b928
commit 0c8cfbb
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:') | ||
|
@@ -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(): | ||
|
@@ -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() |