From 2da7b6914a4258e840b2b81fa7abf7ddcc9643b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Mon, 11 Sep 2023 23:10:17 +0000 Subject: [PATCH] crude admin authentication flow --- api/advent22_api/routers/admin.py | 10 +++++----- ui/src/App.vue | 24 +++++++----------------- ui/src/components/AdminButton.vue | 15 ++++++++++++++- ui/src/components/LoginModal.vue | 2 ++ 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/api/advent22_api/routers/admin.py b/api/advent22_api/routers/admin.py index 93b1ca0..c2edc32 100644 --- a/api/advent22_api/routers/admin.py +++ b/api/advent22_api/routers/admin.py @@ -7,16 +7,16 @@ from ..core.calendar_config import CalendarConfig, get_calendar_config from ..core.config import Config, get_config from ..core.depends import shuffle_solution from ..core.settings import SETTINGS -from ._security import require_admin +from ._security import user_is_admin router = APIRouter(prefix="/admin", tags=["admin"]) -@router.get("/check") -async def check_admin( - _: None = Depends(require_admin), +@router.get("/is_admin") +async def is_admin( + is_admin: bool = Depends(user_is_admin), ) -> bool: - return True + return is_admin class ConfigModel(BaseModel): diff --git a/ui/src/App.vue b/ui/src/App.vue index 28226b3..8589e79 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -1,17 +1,18 @@ @@ -33,18 +34,7 @@ import DoorMapEditor from "./components/DoorMapEditor.vue"; }, }) export default class extends Vue { - private visible_days = 0; - date = ""; - - public mounted() { - this.$advent22 - .api_get("days/date") - .then((date: string) => (this.date = date)); - - this.$advent22 - .api_get("days/visible_days") - .then((visible_days: number) => (this.visible_days = visible_days)); - } + public is_admin = false; } diff --git a/ui/src/components/AdminButton.vue b/ui/src/components/AdminButton.vue index 629c31e..54608ac 100644 --- a/ui/src/components/AdminButton.vue +++ b/ui/src/components/AdminButton.vue @@ -1,5 +1,5 @@