63 lines
1.5 KiB
Python
Executable File
63 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from nicegui import app, ui
|
|
|
|
from auth.login import router as login_router
|
|
from auth.logout import logout
|
|
from auth.mw import AuthMiddleware
|
|
|
|
|
|
app.include_router(login_router)
|
|
app.add_middleware(AuthMiddleware)
|
|
|
|
|
|
@ui.page("/")
|
|
def main_page():
|
|
with ui.column().classes("absolute-center items-center"):
|
|
username = app.storage.user.get("username", "unknown user")
|
|
ui.label(f"Hello {username}!").classes("text-2xl")
|
|
ui.button("log out", icon="logout", on_click=logout)
|
|
|
|
pgroups = app.storage.user.get("pgroups", set())
|
|
ui.select(
|
|
label="pgroup",
|
|
options=sorted(pgroups),
|
|
with_input=True,
|
|
on_change=lambda e: ui.navigate.to(e.value)
|
|
)
|
|
|
|
|
|
|
|
#TODO: the below is a dummy
|
|
|
|
from typing import Annotated
|
|
from fastapi import Path
|
|
|
|
PGroup = Annotated[str, Path(pattern=r"^p\d{5}$")]
|
|
|
|
|
|
@ui.page("/{pgroup}")
|
|
def table(pgroup: PGroup):
|
|
pgroups = app.storage.user.get("pgroups", set())
|
|
if pgroup in pgroups:
|
|
table_show(pgroup)
|
|
else:
|
|
table_deny(pgroup)
|
|
|
|
def table_show(pgroup):
|
|
with ui.column().classes("absolute-center items-center gap-8"):
|
|
ui.icon("sym_o_thumb_up", size="xl")
|
|
ui.label(f"{pgroup} erlaubt!").classes("text-2xl")
|
|
|
|
def table_deny(pgroup):
|
|
with ui.column().classes("absolute-center items-center gap-8"):
|
|
ui.icon("sym_o_front_hand", size="xl")
|
|
ui.label(f"{pgroup} verboten!").classes("text-2xl")
|
|
|
|
|
|
|
|
ui.run(storage_secret="THIS_NEEDS_TO_BE_CHANGED", dark=True) #TODO: storage_secret?
|
|
|
|
|
|
|