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 @@