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