From ab7f4c5ba209bb7b0c9272991658ec5ce5cdccb7 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 3 Apr 2021 01:01:59 +0200 Subject: [PATCH] stages/authenticator_totp: migrate to web Signed-off-by: Jens Langhammer --- authentik/stages/authenticator_totp/forms.py | 17 ---- authentik/stages/authenticator_totp/models.py | 6 +- .../AuthenticatorTOTPStageForm.ts | 98 +++++++++++++++++++ .../identification/IdentificationStageForm.ts | 4 +- 4 files changed, 102 insertions(+), 23 deletions(-) delete mode 100644 authentik/stages/authenticator_totp/forms.py create mode 100644 web/src/pages/stages/authenticator_totp/AuthenticatorTOTPStageForm.ts diff --git a/authentik/stages/authenticator_totp/forms.py b/authentik/stages/authenticator_totp/forms.py deleted file mode 100644 index 98ebe481e..000000000 --- a/authentik/stages/authenticator_totp/forms.py +++ /dev/null @@ -1,17 +0,0 @@ -"""OTP Time forms""" -from django import forms - -from authentik.stages.authenticator_totp.models import AuthenticatorTOTPStage - - -class AuthenticatorTOTPStageForm(forms.ModelForm): - """OTP Time-based Stage setup form""" - - class Meta: - - model = AuthenticatorTOTPStage - fields = ["name", "configure_flow", "digits"] - - widgets = { - "name": forms.TextInput(), - } diff --git a/authentik/stages/authenticator_totp/models.py b/authentik/stages/authenticator_totp/models.py index 80f5044f4..c7ec6e62f 100644 --- a/authentik/stages/authenticator_totp/models.py +++ b/authentik/stages/authenticator_totp/models.py @@ -38,10 +38,8 @@ class AuthenticatorTOTPStage(ConfigurableStage, Stage): return AuthenticatorTOTPStageView @property - def form(self) -> Type[ModelForm]: - from authentik.stages.authenticator_totp.forms import AuthenticatorTOTPStageForm - - return AuthenticatorTOTPStageForm + def component(self) -> str: + return "ak-stage-authenticator-totp-form" @property def ui_user_settings(self) -> Optional[UserSettingSerializer]: diff --git a/web/src/pages/stages/authenticator_totp/AuthenticatorTOTPStageForm.ts b/web/src/pages/stages/authenticator_totp/AuthenticatorTOTPStageForm.ts new file mode 100644 index 000000000..3d1805c61 --- /dev/null +++ b/web/src/pages/stages/authenticator_totp/AuthenticatorTOTPStageForm.ts @@ -0,0 +1,98 @@ +import { FlowDesignationEnum, FlowsApi, AuthenticatorTOTPStage, 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"; +import { until } from "lit-html/directives/until"; + +@customElement("ak-stage-authenticator-totp-form") +export class AuthenticatorTOTPStageForm extends Form { + + set stageUUID(value: string) { + new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorTotpRead({ + stageUuid: value, + }).then(stage => { + this.stage = stage; + }); + } + + @property({attribute: false}) + stage?: AuthenticatorTOTPStage; + + getSuccessMessage(): string { + if (this.stage) { + return gettext("Successfully updated stage."); + } else { + return gettext("Successfully created stage."); + } + } + + send = (data: AuthenticatorTOTPStage): Promise => { + if (this.stage) { + return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorTotpUpdate({ + stageUuid: this.stage.pk || "", + data: data + }); + } else { + return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorTotpCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + + + + ${gettext("Stage-specific settings")} + +
+ + + + + +

${gettext("Flow used by an authenticated user to configure this Stage. If empty, user will not be able to configure this stage.")}

+
+
+
+
`; + } + +} diff --git a/web/src/pages/stages/identification/IdentificationStageForm.ts b/web/src/pages/stages/identification/IdentificationStageForm.ts index b5b5138c6..9b0fadadb 100644 --- a/web/src/pages/stages/identification/IdentificationStageForm.ts +++ b/web/src/pages/stages/identification/IdentificationStageForm.ts @@ -69,10 +69,10 @@ export class IdentificationStageForm extends Form { name="transports">

${gettext("Fields a user can identify themselves with.")}