This commit is contained in:
Edward Betts 2024-01-22 12:46:13 +00:00
commit cc3dc81bdb
2 changed files with 11 additions and 7 deletions

View file

@ -20,13 +20,17 @@ def verify_auth_token(token: str) -> str | None:
def require_authentication() -> werkzeug.Response | None: def require_authentication() -> werkzeug.Response | None:
"""Require authentication.""" """Require authentication and redirect with return URL."""
if not flask.current_app.config.get("REQUIRE_AUTH"): if not flask.current_app.config.get("REQUIRE_AUTH"):
return None return None
token = flask.request.cookies.get("auth_token") token = flask.request.cookies.get("auth_token")
return ( if token and verify_auth_token(token):
None return None
if token and verify_auth_token(token)
else flask.redirect(flask.current_app.config["UNIAUTH_URL"] + "/login") # Construct the redirect URL with the original URL as a parameter
return flask.redirect(
flask.current_app.config["UNIAUTH_URL"]
+ "/login?next="
+ werkzeug.urls.url_quote(flask.request.url)
) )

View file

@ -70,12 +70,12 @@ async def index() -> str:
@app.route("/launches") @app.route("/launches")
async def launch_list() -> str: def launch_list() -> str:
"""Web page showing List of space launches.""" """Web page showing List of space launches."""
now = datetime.now() now = datetime.now()
data_dir = app.config["DATA_DIR"] data_dir = app.config["DATA_DIR"]
rocket_dir = os.path.join(data_dir, "thespacedevs") rocket_dir = os.path.join(data_dir, "thespacedevs")
rockets = await agenda.thespacedevs.get_launches(rocket_dir, limit=100) rockets = agenda.thespacedevs.get_launches(rocket_dir, limit=100)
return flask.render_template( return flask.render_template(
"launches.html", rockets=rockets, now=now, get_country=agenda.get_country "launches.html", rockets=rockets, now=now, get_country=agenda.get_country