From fb9a4ec461ce50a29cc2edeec7f8361257a758f4 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 2 Apr 2021 23:51:39 +0200 Subject: [PATCH] stages/user_login: migrate to web Signed-off-by: Jens Langhammer --- authentik/stages/user_login/forms.py | 17 ----- authentik/stages/user_login/models.py | 7 +- .../stages/user_login/UserLoginStageForm.ts | 70 +++++++++++++++++++ 3 files changed, 72 insertions(+), 22 deletions(-) delete mode 100644 authentik/stages/user_login/forms.py create mode 100644 web/src/pages/stages/user_login/UserLoginStageForm.ts diff --git a/authentik/stages/user_login/forms.py b/authentik/stages/user_login/forms.py deleted file mode 100644 index 8693a7892..000000000 --- a/authentik/stages/user_login/forms.py +++ /dev/null @@ -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(), - } diff --git a/authentik/stages/user_login/models.py b/authentik/stages/user_login/models.py index db885dbd3..4d47a449f 100644 --- a/authentik/stages/user_login/models.py +++ b/authentik/stages/user_login/models.py @@ -2,7 +2,6 @@ from typing import Type from django.db import models -from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ from django.views import View from rest_framework.serializers import BaseSerializer @@ -37,10 +36,8 @@ class UserLoginStage(Stage): return UserLoginStageView @property - def form(self) -> Type[ModelForm]: - from authentik.stages.user_login.forms import UserLoginStageForm - - return UserLoginStageForm + def component(self) -> str: + return "ak-stage-user-login-form" class Meta: diff --git a/web/src/pages/stages/user_login/UserLoginStageForm.ts b/web/src/pages/stages/user_login/UserLoginStageForm.ts new file mode 100644 index 000000000..183570c7e --- /dev/null +++ b/web/src/pages/stages/user_login/UserLoginStageForm.ts @@ -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 { + + 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 => { + 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`
+ + + + + + ${gettext("Stage-specific settings")} + +
+ + +

${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).")}

+
+
+
+
`; + } + +}