Add logged_out redirect (#227)

master
reality500 2022-04-13 18:54:32 -04:00 committed by GitHub
parent 8c25a48d0c
commit 5d6885e5bf
1 changed files with 19 additions and 1 deletions

View File

@ -16,6 +16,24 @@ def rdrama(id, title):
id = ''.join(f'{x}/' for x in id) id = ''.join(f'{x}/' for x in id)
return redirect(f'/archives/drama/comments/{id}{title}.html') return redirect(f'/archives/drama/comments/{id}{title}.html')
@app.get('/logged_out/')
@app.get('/logged_out/<path:old>')
def logged_out(old = ""):
# Remove trailing question mark from request.full_path which flask adds if there are no query parameters
redirect_url = request.full_path.replace("/logged_out", "", 1)
if redirect_url.endswith("?"):
redirect_url = redirect_url[:-1]
# Handle cases like /logged_out?asdf by adding a slash to the beginning
if not redirect_url.startswith('/'):
redirect_url = f"/{redirect_url}"
# Prevent redirect loop caused by visiting /logged_out/logged_out/logged_out/etc...
if redirect_url.startswith('/logged_out'):
abort(400)
return redirect(redirect_url)
@app.get("/privacy") @app.get("/privacy")
@auth_required @auth_required
def privacy(v): def privacy(v):
@ -438,4 +456,4 @@ def googleplayapp():
@app.post("/dismiss_mobile_tip") @app.post("/dismiss_mobile_tip")
def dismiss_mobile_tip(): def dismiss_mobile_tip():
session["tooltip_last_dismissed"] = int(time.time()) session["tooltip_last_dismissed"] = int(time.time())
return "", 204 return "", 204