From b30e8095f98b4e421732e6ecf2ffa6d4a7f48d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Mon, 11 Sep 2023 23:36:36 +0000 Subject: [PATCH] way better admin login flow --- api/advent22_api/routers/admin.py | 2 +- ui/src/components/AdminButton.vue | 29 ++++++--- ui/src/components/LoginModal.vue | 101 ++++++++++++++---------------- ui/src/plugins/advent22.ts | 4 ++ 4 files changed, 74 insertions(+), 62 deletions(-) diff --git a/api/advent22_api/routers/admin.py b/api/advent22_api/routers/admin.py index c2edc32..41063e2 100644 --- a/api/advent22_api/routers/admin.py +++ b/api/advent22_api/routers/admin.py @@ -7,7 +7,7 @@ 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 user_is_admin +from ._security import require_admin, user_is_admin router = APIRouter(prefix="/admin", tags=["admin"]) diff --git a/ui/src/components/AdminButton.vue b/ui/src/components/AdminButton.vue index 54608ac..5cef5f7 100644 --- a/ui/src/components/AdminButton.vue +++ b/ui/src/components/AdminButton.vue @@ -1,10 +1,14 @@ @@ -28,12 +32,23 @@ import LoginModal from "./LoginModal.vue"; export default class extends Vue { // true, iff Benutzer Admin ist public modelValue!: boolean; + public modal_visible = false; - declare $refs: { - login_modal: LoginModal; - }; + public on_click() { + if (this.modelValue) { + // logout + this.$advent22.clear_api_auth(); + this.$emit("update:modelValue", false); + } else { + // show login modal + this.modal_visible = true; + } + } + + public on_submit(username: string, password: string) { + this.modal_visible = false; + this.$advent22.set_api_auth(username, password); - public on_login() { this.$advent22 .api_get("admin/is_admin") .then((is_admin) => this.$emit("update:modelValue", is_admin)); diff --git a/ui/src/components/LoginModal.vue b/ui/src/components/LoginModal.vue index 47e06b7..c1e0cb6 100644 --- a/ui/src/components/LoginModal.vue +++ b/ui/src/components/LoginModal.vue @@ -1,50 +1,48 @@