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.config import Config, get_config
|
||||||
from ..core.depends import shuffle_solution
|
from ..core.depends import shuffle_solution
|
||||||
from ..core.settings import SETTINGS
|
from ..core.settings import SETTINGS
|
||||||
from ._security import require_admin
|
from ._security import user_is_admin
|
||||||
|
|
||||||
router = APIRouter(prefix="/admin", tags=["admin"])
|
router = APIRouter(prefix="/admin", tags=["admin"])
|
||||||
|
|
||||||
|
|
||||||
@router.get("/check")
|
@router.get("/is_admin")
|
||||||
async def check_admin(
|
async def is_admin(
|
||||||
_: None = Depends(require_admin),
|
is_admin: bool = Depends(user_is_admin),
|
||||||
) -> bool:
|
) -> bool:
|
||||||
return True
|
return is_admin
|
||||||
|
|
||||||
|
|
||||||
class ConfigModel(BaseModel):
|
class ConfigModel(BaseModel):
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<h1 class="title has-text-centered is-uppercase">
|
<h1 class="title has-text-centered is-uppercase">Adventskalender</h1>
|
||||||
Adventskalender {{ date }}
|
|
||||||
</h1>
|
|
||||||
<h2 class="subtitle has-text-centered">Der Gelöt</h2>
|
<h2 class="subtitle has-text-centered">Der Gelöt</h2>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="section">
|
<section v-if="is_admin" class="section">
|
||||||
<ConfigView />
|
<ConfigView />
|
||||||
<CalendarAssistant />
|
<CalendarAssistant />
|
||||||
<DoorMapEditor />
|
<DoorMapEditor />
|
||||||
<AdminButton />
|
</section>
|
||||||
|
|
||||||
|
<section class="section">
|
||||||
|
<AdminButton v-model="is_admin" />
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -33,18 +34,7 @@ import DoorMapEditor from "./components/DoorMapEditor.vue";
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
private visible_days = 0;
|
public is_admin = false;
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<LoginModal ref="login_modal" />
|
<LoginModal ref="login_modal" @submit="on_login" />
|
||||||
|
|
||||||
<BulmaButton
|
<BulmaButton
|
||||||
class="button is-light"
|
class="button is-light"
|
||||||
|
@ -20,10 +20,23 @@ import LoginModal from "./LoginModal.vue";
|
||||||
BulmaButton,
|
BulmaButton,
|
||||||
LoginModal,
|
LoginModal,
|
||||||
},
|
},
|
||||||
|
props: {
|
||||||
|
modelValue: Boolean,
|
||||||
|
},
|
||||||
|
emits: ["update:modelValue"],
|
||||||
})
|
})
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
|
// true, iff Benutzer Admin ist
|
||||||
|
public modelValue!: boolean;
|
||||||
|
|
||||||
declare $refs: {
|
declare $refs: {
|
||||||
login_modal: LoginModal;
|
login_modal: LoginModal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public on_login() {
|
||||||
|
this.$advent22
|
||||||
|
.api_get<boolean>("admin/is_admin")
|
||||||
|
.then((is_admin) => this.$emit("update:modelValue", is_admin));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -62,6 +62,7 @@ import BulmaButton from "./bulma/Button.vue";
|
||||||
components: {
|
components: {
|
||||||
BulmaButton,
|
BulmaButton,
|
||||||
},
|
},
|
||||||
|
emits: ["submit"],
|
||||||
})
|
})
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
public active = false;
|
public active = false;
|
||||||
|
@ -95,6 +96,7 @@ export default class extends Vue {
|
||||||
|
|
||||||
public submit() {
|
public submit() {
|
||||||
this.$advent22.set_api_auth(this.username, this.password);
|
this.$advent22.set_api_auth(this.username, this.password);
|
||||||
|
this.$emit("submit");
|
||||||
this.set_active(false);
|
this.set_active(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue