From 224ad46a21f9a2df450731c231a503470618fc23 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 2 Apr 2021 23:45:39 +0200 Subject: [PATCH] stages/captcha: migrate to web Signed-off-by: Jens Langhammer --- authentik/stages/captcha/forms.py | 18 ----- authentik/stages/captcha/models.py | 6 +- .../pages/stages/captcha/CaptchaStageForm.ts | 76 +++++++++++++++++++ 3 files changed, 78 insertions(+), 22 deletions(-) delete mode 100644 authentik/stages/captcha/forms.py create mode 100644 web/src/pages/stages/captcha/CaptchaStageForm.ts diff --git a/authentik/stages/captcha/forms.py b/authentik/stages/captcha/forms.py deleted file mode 100644 index 7902bcbd7..000000000 --- a/authentik/stages/captcha/forms.py +++ /dev/null @@ -1,18 +0,0 @@ -"""authentik captcha stage forms""" -from django import forms - -from authentik.stages.captcha.models import CaptchaStage - - -class CaptchaStageForm(forms.ModelForm): - """Form to edit CaptchaStage Instance""" - - class Meta: - - model = CaptchaStage - fields = ["name", "public_key", "private_key"] - widgets = { - "name": forms.TextInput(), - "public_key": forms.TextInput(), - "private_key": forms.TextInput(), - } diff --git a/authentik/stages/captcha/models.py b/authentik/stages/captcha/models.py index d2a0fe501..61db9f375 100644 --- a/authentik/stages/captcha/models.py +++ b/authentik/stages/captcha/models.py @@ -37,10 +37,8 @@ class CaptchaStage(Stage): return CaptchaStageView @property - def form(self) -> Type[ModelForm]: - from authentik.stages.captcha.forms import CaptchaStageForm - - return CaptchaStageForm + def component(self) -> str: + return "ak-stage-captcha-form" class Meta: diff --git a/web/src/pages/stages/captcha/CaptchaStageForm.ts b/web/src/pages/stages/captcha/CaptchaStageForm.ts new file mode 100644 index 000000000..4fbb6f2b4 --- /dev/null +++ b/web/src/pages/stages/captcha/CaptchaStageForm.ts @@ -0,0 +1,76 @@ +import { CaptchaStage, 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-captcha-form") +export class CaptchaStageForm extends Form { + + set stageUUID(value: string) { + new StagesApi(DEFAULT_CONFIG).stagesCaptchaRead({ + stageUuid: value, + }).then(stage => { + this.stage = stage; + }); + } + + @property({attribute: false}) + stage?: CaptchaStage; + + getSuccessMessage(): string { + if (this.stage) { + return gettext("Successfully updated stage."); + } else { + return gettext("Successfully created stage."); + } + } + + send = (data: CaptchaStage): Promise => { + if (this.stage) { + return new StagesApi(DEFAULT_CONFIG).stagesCaptchaUpdate({ + stageUuid: this.stage.pk || "", + data: data + }); + } else { + return new StagesApi(DEFAULT_CONFIG).stagesCaptchaCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + + + + ${gettext("Stage-specific settings")} + +
+ + +

${gettext("Public key, acquired from https://www.google.com/recaptcha/intro/v3.html.")}

+
+ + +

${gettext("Public key, acquired from https://www.google.com/recaptcha/intro/v3.html.")}

+
+
+
+
`; + } + +}