merged authenticated.py into stand.py
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
#!/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
|
||||
from auth.secret import get_secret
|
||||
|
||||
|
||||
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=get_secret(), dark=True)
|
||||
|
||||
|
||||
|
||||
@@ -9,10 +9,19 @@ import pandas as pd
|
||||
from fastapi import APIRouter, Path
|
||||
from nicegui import app, ui
|
||||
|
||||
from auth.login import router as login_router
|
||||
from auth.logout import logout
|
||||
from auth.mw import AuthMiddleware
|
||||
from auth.secret import get_secret
|
||||
|
||||
from aggridx import aggridx
|
||||
from registry import Registry
|
||||
|
||||
|
||||
app.include_router(login_router)
|
||||
app.add_middleware(AuthMiddleware)
|
||||
|
||||
|
||||
PGroup = Annotated[str, Path(pattern=r"^p\d{5}$")]
|
||||
|
||||
|
||||
@@ -77,8 +86,32 @@ def update_grids(evt):
|
||||
grid.set_cell_client(row_id, col_id, new_val)
|
||||
|
||||
|
||||
@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)
|
||||
)
|
||||
|
||||
|
||||
@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.left_drawer(value=False) as ld:
|
||||
# dark = ui.dark_mode(value=True)
|
||||
# ui.switch("dark mode").bind_value(dark)
|
||||
@@ -106,6 +139,12 @@ def table(pgroup: PGroup):
|
||||
grids[pgroup].add(grid)
|
||||
|
||||
|
||||
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")
|
||||
|
||||
|
||||
@router.post("/{pgroup}/append")
|
||||
def append(pgroup: PGroup, row: dict[str, Any]):
|
||||
now = datetime.now()
|
||||
@@ -126,7 +165,7 @@ def append(pgroup: PGroup, row: dict[str, Any]):
|
||||
|
||||
app.include_router(router)
|
||||
|
||||
ui.run(title="stand", favicon="favicon.png", fastapi_docs=True, dark=True, show=False)
|
||||
ui.run(title="stand", favicon="favicon.png", storage_secret=get_secret(), fastapi_docs=True, dark=True, show=False)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user