Răsfoiți Sursa

redirect to login when session expires

Karl Hudgell 3 săptămâni în urmă
părinte
comite
554359d7f5
1 a modificat fișierele cu 14 adăugiri și 12 ștergeri
  1. 14 12
      app.py

+ 14 - 12
app.py

@@ -41,18 +41,20 @@ def index():
 @app.route("/home")
 @cache.cached(timeout=60)  # cache for 120 seconds
 def home():
-    base_url = app.config["BASE_URL"]  # Access base_url from the config
-    all_accounts = get_user_accounts(base_url, session["auth_credentials"])
-    count = len(all_accounts)
-    current_month_accounts = filter_accounts_current_month(all_accounts)
-    expired_accounts = filter_accounts_expired(all_accounts)
-    return render_template(
-        "home.html",
-        username=session["username"],
-        accounts=count,
-        current_month_accounts=current_month_accounts,
-        expired_accounts=expired_accounts,
-    )
+    if session.get("logged_in"):
+        base_url = app.config["BASE_URL"]  # Access base_url from the config
+        all_accounts = get_user_accounts(base_url, session["auth_credentials"])
+        count = len(all_accounts)
+        current_month_accounts = filter_accounts_current_month(all_accounts)
+        expired_accounts = filter_accounts_expired(all_accounts)
+        return render_template(
+            "home.html",
+            username=session["username"],
+            accounts=count,
+            current_month_accounts=current_month_accounts,
+            expired_accounts=expired_accounts,
+        )
+    return render_template("index.html")
 
 
 @app.route("/login", methods=["POST"])