stages/user_logout: migrate to web

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-02 23:52:55 +02:00
parent fb9a4ec461
commit 128af67011
3 changed files with 58 additions and 21 deletions

View file

@ -1,16 +0,0 @@
"""authentik flows logout forms"""
from django import forms
from authentik.stages.user_logout.models import UserLogoutStage
class UserLogoutStageForm(forms.ModelForm):
"""Form to create/edit UserLogoutStage instances"""
class Meta:
model = UserLogoutStage
fields = ["name"]
widgets = {
"name": forms.TextInput(),
}

View file

@ -1,7 +1,6 @@
"""logout stage models"""
from typing import Type
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _
from django.views import View
from rest_framework.serializers import BaseSerializer
@ -25,10 +24,8 @@ class UserLogoutStage(Stage):
return UserLogoutStageView
@property
def form(self) -> Type[ModelForm]:
from authentik.stages.user_logout.forms import UserLogoutStageForm
return UserLogoutStageForm
def component(self) -> str:
return "ak-stage-user-logout-form"
class Meta:

View file

@ -0,0 +1,56 @@
import { UserLogoutStage, StagesApi } from "authentik-api";
import { gettext } from "django";
import { customElement, property } from "lit-element";
import { html, TemplateResult } from "lit-html";
import { DEFAULT_CONFIG } from "../../../api/Config";
import { Form } from "../../../elements/forms/Form";
import { ifDefined } from "lit-html/directives/if-defined";
import "../../../elements/forms/HorizontalFormElement";
@customElement("ak-stage-user-logout-form")
export class UserLogoutStageForm extends Form<UserLogoutStage> {
set stageUUID(value: string) {
new StagesApi(DEFAULT_CONFIG).stagesUserLogoutRead({
stageUuid: value,
}).then(stage => {
this.stage = stage;
});
}
@property({attribute: false})
stage?: UserLogoutStage;
getSuccessMessage(): string {
if (this.stage) {
return gettext("Successfully updated stage.");
} else {
return gettext("Successfully created stage.");
}
}
send = (data: UserLogoutStage): Promise<UserLogoutStage> => {
if (this.stage) {
return new StagesApi(DEFAULT_CONFIG).stagesUserLogoutUpdate({
stageUuid: this.stage.pk || "",
data: data
});
} else {
return new StagesApi(DEFAULT_CONFIG).stagesUserLogoutCreate({
data: data
});
}
};
renderForm(): TemplateResult {
return html`<form class="pf-c-form pf-m-horizontal">
<ak-form-element-horizontal
label=${gettext("Name")}
?required=${true}
name="name">
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
</ak-form-element-horizontal>
</form>`;
}
}