stages/user_login: migrate to web
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
2a261cfaf8
commit
fb9a4ec461
|
@ -1,17 +0,0 @@
|
||||||
"""authentik flows login forms"""
|
|
||||||
from django import forms
|
|
||||||
|
|
||||||
from authentik.stages.user_login.models import UserLoginStage
|
|
||||||
|
|
||||||
|
|
||||||
class UserLoginStageForm(forms.ModelForm):
|
|
||||||
"""Form to create/edit UserLoginStage instances"""
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
|
|
||||||
model = UserLoginStage
|
|
||||||
fields = ["name", "session_duration"]
|
|
||||||
widgets = {
|
|
||||||
"name": forms.TextInput(),
|
|
||||||
"session_duration": forms.TextInput(),
|
|
||||||
}
|
|
|
@ -2,7 +2,6 @@
|
||||||
from typing import Type
|
from typing import Type
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.forms import ModelForm
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from rest_framework.serializers import BaseSerializer
|
from rest_framework.serializers import BaseSerializer
|
||||||
|
@ -37,10 +36,8 @@ class UserLoginStage(Stage):
|
||||||
return UserLoginStageView
|
return UserLoginStageView
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def form(self) -> Type[ModelForm]:
|
def component(self) -> str:
|
||||||
from authentik.stages.user_login.forms import UserLoginStageForm
|
return "ak-stage-user-login-form"
|
||||||
|
|
||||||
return UserLoginStageForm
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
import { UserLoginStage, 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";
|
||||||
|
import "../../../elements/forms/FormGroup";
|
||||||
|
|
||||||
|
@customElement("ak-stage-user-login-form")
|
||||||
|
export class UserLoginStageForm extends Form<UserLoginStage> {
|
||||||
|
|
||||||
|
set stageUUID(value: string) {
|
||||||
|
new StagesApi(DEFAULT_CONFIG).stagesUserLoginRead({
|
||||||
|
stageUuid: value,
|
||||||
|
}).then(stage => {
|
||||||
|
this.stage = stage;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@property({attribute: false})
|
||||||
|
stage?: UserLoginStage;
|
||||||
|
|
||||||
|
getSuccessMessage(): string {
|
||||||
|
if (this.stage) {
|
||||||
|
return gettext("Successfully updated stage.");
|
||||||
|
} else {
|
||||||
|
return gettext("Successfully created stage.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
send = (data: UserLoginStage): Promise<UserLoginStage> => {
|
||||||
|
if (this.stage) {
|
||||||
|
return new StagesApi(DEFAULT_CONFIG).stagesUserLoginUpdate({
|
||||||
|
stageUuid: this.stage.pk || "",
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return new StagesApi(DEFAULT_CONFIG).stagesUserLoginCreate({
|
||||||
|
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>
|
||||||
|
<ak-form-group .expanded=${true}>
|
||||||
|
<span slot="header">
|
||||||
|
${gettext("Stage-specific settings")}
|
||||||
|
</span>
|
||||||
|
<div slot="body" class="pf-c-form">
|
||||||
|
<ak-form-element-horizontal
|
||||||
|
label=${gettext("Session duration")}
|
||||||
|
name="privateKey">
|
||||||
|
<input type="text" value="${ifDefined(this.stage?.sessionDuration || "seconds=0")}" class="pf-c-form-control">
|
||||||
|
<p class="pf-c-form__helper-text">${gettext("Determines how long a session lasts. Default of 0 seconds means that the sessions lasts until the browser is closed. (Format: hours=-1;minutes=-2;seconds=-3).")}</p>
|
||||||
|
</ak-form-element-horizontal>
|
||||||
|
</div>
|
||||||
|
</ak-form-group>
|
||||||
|
</form>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue