mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 00:03:07 +00:00
crude admin authentication flow
This commit is contained in:
parent
26556ad309
commit
2da7b6914a
4 changed files with 28 additions and 23 deletions
|
@ -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):
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
<template>
|
||||
<div class="container">
|
||||
<section class="section">
|
||||
<h1 class="title has-text-centered is-uppercase">
|
||||
Adventskalender {{ date }}
|
||||
</h1>
|
||||
<h1 class="title has-text-centered is-uppercase">Adventskalender</h1>
|
||||
<h2 class="subtitle has-text-centered">Der Gelöt</h2>
|
||||
</section>
|
||||
|
||||
<section class="section">
|
||||
<section v-if="is_admin" class="section">
|
||||
<ConfigView />
|
||||
<CalendarAssistant />
|
||||
<DoorMapEditor />
|
||||
<AdminButton />
|
||||
</section>
|
||||
|
||||
<section class="section">
|
||||
<AdminButton v-model="is_admin" />
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -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<string>("days/date")
|
||||
.then((date: string) => (this.date = date));
|
||||
|
||||
this.$advent22
|
||||
.api_get<number>("days/visible_days")
|
||||
.then((visible_days: number) => (this.visible_days = visible_days));
|
||||
}
|
||||
public is_admin = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<LoginModal ref="login_modal" />
|
||||
<LoginModal ref="login_modal" @submit="on_login" />
|
||||
|
||||
<BulmaButton
|
||||
class="button is-light"
|
||||
|
@ -20,10 +20,23 @@ import LoginModal from "./LoginModal.vue";
|
|||
BulmaButton,
|
||||
LoginModal,
|
||||
},
|
||||
props: {
|
||||
modelValue: Boolean,
|
||||
},
|
||||
emits: ["update:modelValue"],
|
||||
})
|
||||
export default class extends Vue {
|
||||
// true, iff Benutzer Admin ist
|
||||
public modelValue!: boolean;
|
||||
|
||||
declare $refs: {
|
||||
login_modal: LoginModal;
|
||||
};
|
||||
|
||||
public on_login() {
|
||||
this.$advent22
|
||||
.api_get<boolean>("admin/is_admin")
|
||||
.then((is_admin) => this.$emit("update:modelValue", is_admin));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -62,6 +62,7 @@ import BulmaButton from "./bulma/Button.vue";
|
|||
components: {
|
||||
BulmaButton,
|
||||
},
|
||||
emits: ["submit"],
|
||||
})
|
||||
export default class extends Vue {
|
||||
public active = false;
|
||||
|
@ -95,6 +96,7 @@ export default class extends Vue {
|
|||
|
||||
public submit() {
|
||||
this.$advent22.set_api_auth(this.username, this.password);
|
||||
this.$emit("submit");
|
||||
this.set_active(false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue