You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
from functools import wraps |
|
|
|
from flask import Blueprint, redirect, render_template, session, url_for |
|
|
|
from app.db import get_db |
|
|
|
bp = Blueprint("main", __name__) |
|
|
|
def portal_session_required(view_func): |
|
@wraps(view_func) |
|
def wrapped(*args, **kwargs): |
|
if "otb_user_id" not in session or "otb_tenant_id" not in session: |
|
return redirect(url_for("auth.login_required_notice")) |
|
return view_func(*args, **kwargs) |
|
return wrapped |
|
|
|
@bp.route("/") |
|
def index(): |
|
if "otb_user_id" in session: |
|
return redirect(url_for("main.dashboard")) |
|
return redirect(url_for("auth.login_required_notice")) |
|
|
|
@bp.route("/dashboard") |
|
@portal_session_required |
|
def dashboard(): |
|
db = get_db() |
|
|
|
with db.cursor() as cur: |
|
cur.execute( |
|
""" |
|
SELECT id, device_name, device_type, relative_path, is_active, created_at |
|
FROM devices |
|
WHERE tenant_id = %s |
|
ORDER BY id |
|
""", |
|
(session["otb_tenant_id"],), |
|
) |
|
devices = cur.fetchall() |
|
|
|
return render_template( |
|
"cloud/dashboard.html", |
|
user_email=session.get("otb_email"), |
|
tenant_slug=session.get("otb_tenant_slug"), |
|
devices=devices, |
|
)
|
|
|