web/elements: add ?writeOnly flag for passwords etc
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
597bd472ea
commit
93b362570d
|
@ -210,6 +210,9 @@ body {
|
||||||
--pf-c-form-control--BackgroundColor: var(--ak-dark-background-light);
|
--pf-c-form-control--BackgroundColor: var(--ak-dark-background-light);
|
||||||
color: var(--ak-dark-foreground);
|
color: var(--ak-dark-foreground);
|
||||||
}
|
}
|
||||||
|
.pf-c-form-control:disabled {
|
||||||
|
background-color: var(--ak-dark-background-light);
|
||||||
|
}
|
||||||
.pf-c-form-control[readonly] {
|
.pf-c-form-control[readonly] {
|
||||||
background-color: var(--ak-dark-background-light);
|
background-color: var(--ak-dark-background-light);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,9 @@ export class Form<T> extends LitElement {
|
||||||
const json: { [key: string]: unknown } = {};
|
const json: { [key: string]: unknown } = {};
|
||||||
elements.forEach(element => {
|
elements.forEach(element => {
|
||||||
const values = form._serializeElementValues(element);
|
const values = form._serializeElementValues(element);
|
||||||
|
if (element.hidden) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (element.tagName.toLowerCase() === "select" && "multiple" in element.attributes) {
|
if (element.tagName.toLowerCase() === "select" && "multiple" in element.attributes) {
|
||||||
json[element.name] = values;
|
json[element.name] = values;
|
||||||
} else if (element.tagName.toLowerCase() === "input" && element.type === "date") {
|
} else if (element.tagName.toLowerCase() === "input" && element.type === "date") {
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
import { customElement, LitElement, CSSResult, property, css } from "lit-element";
|
import { customElement, LitElement, CSSResult, property, css } from "lit-element";
|
||||||
import { TemplateResult, html } from "lit-html";
|
import { TemplateResult, html } from "lit-html";
|
||||||
|
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
||||||
import PFForm from "@patternfly/patternfly/components/Form/form.css";
|
import PFForm from "@patternfly/patternfly/components/Form/form.css";
|
||||||
import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css";
|
import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css";
|
||||||
|
import AKGlobal from "../../authentik.css";
|
||||||
|
import { t } from "@lingui/macro";
|
||||||
|
|
||||||
@customElement("ak-form-element-horizontal")
|
@customElement("ak-form-element-horizontal")
|
||||||
export class HorizontalFormElement extends LitElement {
|
export class HorizontalFormElement extends LitElement {
|
||||||
|
|
||||||
static get styles(): CSSResult[] {
|
static get styles(): CSSResult[] {
|
||||||
return [PFForm, PFFormControl, css`
|
return [PFBase, PFForm, PFFormControl, AKGlobal, css`
|
||||||
.pf-c-form__group {
|
.pf-c-form__group {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: var(--pf-c-form--m-horizontal__group-label--md--GridColumnWidth) var(--pf-c-form--m-horizontal__group-control--md--GridColumnWidth);
|
grid-template-columns: var(--pf-c-form--m-horizontal__group-label--md--GridColumnWidth) var(--pf-c-form--m-horizontal__group-control--md--GridColumnWidth);
|
||||||
|
@ -24,6 +27,12 @@ export class HorizontalFormElement extends LitElement {
|
||||||
@property({ type: Boolean })
|
@property({ type: Boolean })
|
||||||
required = false;
|
required = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean })
|
||||||
|
writeOnly = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean })
|
||||||
|
writeOnlyActivated = false;
|
||||||
|
|
||||||
@property()
|
@property()
|
||||||
errorMessage = "";
|
errorMessage = "";
|
||||||
|
|
||||||
|
@ -46,7 +55,17 @@ export class HorizontalFormElement extends LitElement {
|
||||||
(input as HTMLInputElement).name = this.name;
|
(input as HTMLInputElement).name = this.name;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
return;
|
||||||
|
}
|
||||||
|
if (this.writeOnly && !this.writeOnlyActivated) {
|
||||||
|
const i = (input as HTMLInputElement);
|
||||||
|
i.setAttribute("hidden", "true");
|
||||||
|
const handler = (ev: Event) => {
|
||||||
|
i.removeAttribute("hidden");
|
||||||
|
this.writeOnlyActivated = true;
|
||||||
|
i.parentElement?.removeEventListener("click", handler);
|
||||||
|
};
|
||||||
|
i.parentElement?.addEventListener("click", handler);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -60,8 +79,16 @@ export class HorizontalFormElement extends LitElement {
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="pf-c-form__group-control">
|
<div class="pf-c-form__group-control">
|
||||||
|
${this.writeOnly && !this.writeOnlyActivated ?
|
||||||
|
html`<div class="pf-c-form__horizontal-group">
|
||||||
|
<input class="pf-c-form-control" type="password" disabled value="**************">
|
||||||
|
</div>` :
|
||||||
|
html``}
|
||||||
<slot class="pf-c-form__horizontal-group"></slot>
|
<slot class="pf-c-form__horizontal-group"></slot>
|
||||||
<div class="pf-c-form__horizontal-group">
|
<div class="pf-c-form__horizontal-group">
|
||||||
|
${this.writeOnly ? html`<p class="pf-c-form__helper-text" aria-live="polite">${
|
||||||
|
t`Click to change value`
|
||||||
|
}</p>` : html``}
|
||||||
${this.invalid ? html`<p class="pf-c-form__helper-text pf-m-error" aria-live="polite">${this.errorMessage}</p>` : html``}
|
${this.invalid ? html`<p class="pf-c-form__helper-text pf-m-error" aria-live="polite">${this.errorMessage}</p>` : html``}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -48,12 +48,14 @@ export class CertificateKeyPairForm extends Form<CertificateKeyPair> {
|
||||||
<ak-form-element-horizontal
|
<ak-form-element-horizontal
|
||||||
label=${t`Certificate`}
|
label=${t`Certificate`}
|
||||||
name="certificateData"
|
name="certificateData"
|
||||||
|
?writeOnly=${true}
|
||||||
?required=${true}>
|
?required=${true}>
|
||||||
<textarea class="pf-c-form-control" required>${ifDefined(this.keyPair?.certificateData)}</textarea>
|
<textarea class="pf-c-form-control" required>${ifDefined(this.keyPair?.certificateData)}</textarea>
|
||||||
<p class="pf-c-form__helper-text">${t`PEM-encoded Certificate data.`}</p>
|
<p class="pf-c-form__helper-text">${t`PEM-encoded Certificate data.`}</p>
|
||||||
</ak-form-element-horizontal>
|
</ak-form-element-horizontal>
|
||||||
<ak-form-element-horizontal
|
<ak-form-element-horizontal
|
||||||
name="keyData"
|
name="keyData"
|
||||||
|
?writeOnly=${true}
|
||||||
label=${t`Private Key`}>
|
label=${t`Private Key`}>
|
||||||
<textarea class="pf-c-form-control" >${ifDefined(this.keyPair?.keyData)}</textarea>
|
<textarea class="pf-c-form-control" >${ifDefined(this.keyPair?.keyData)}</textarea>
|
||||||
<p class="pf-c-form__helper-text">${t`Optional Private Key. If this is set, you can use this keypair for encryption.`}</p>
|
<p class="pf-c-form__helper-text">${t`Optional Private Key. If this is set, you can use this keypair for encryption.`}</p>
|
||||||
|
|
|
@ -34,7 +34,7 @@ export class LDAPSourceForm extends Form<LDAPSource> {
|
||||||
|
|
||||||
send = (data: LDAPSource): Promise<LDAPSource> => {
|
send = (data: LDAPSource): Promise<LDAPSource> => {
|
||||||
if (this.source) {
|
if (this.source) {
|
||||||
return new SourcesApi(DEFAULT_CONFIG).sourcesLdapUpdate({
|
return new SourcesApi(DEFAULT_CONFIG).sourcesLdapPartialUpdate({
|
||||||
slug: this.source.slug,
|
slug: this.source.slug,
|
||||||
data: data
|
data: data
|
||||||
});
|
});
|
||||||
|
@ -119,6 +119,7 @@ export class LDAPSourceForm extends Form<LDAPSource> {
|
||||||
<ak-form-element-horizontal
|
<ak-form-element-horizontal
|
||||||
label=${t`Bind Password`}
|
label=${t`Bind Password`}
|
||||||
?required=${true}
|
?required=${true}
|
||||||
|
?writeOnly=${true}
|
||||||
name="bindPassword">
|
name="bindPassword">
|
||||||
<input type="text" value="${ifDefined(this.source?.bindPassword)}" class="pf-c-form-control" required>
|
<input type="text" value="${ifDefined(this.source?.bindPassword)}" class="pf-c-form-control" required>
|
||||||
</ak-form-element-horizontal>
|
</ak-form-element-horizontal>
|
||||||
|
|
|
@ -32,7 +32,7 @@ export class CaptchaStageForm extends Form<CaptchaStage> {
|
||||||
|
|
||||||
send = (data: CaptchaStage): Promise<CaptchaStage> => {
|
send = (data: CaptchaStage): Promise<CaptchaStage> => {
|
||||||
if (this.stage) {
|
if (this.stage) {
|
||||||
return new StagesApi(DEFAULT_CONFIG).stagesCaptchaUpdate({
|
return new StagesApi(DEFAULT_CONFIG).stagesCaptchaPartialUpdate({
|
||||||
stageUuid: this.stage.pk || "",
|
stageUuid: this.stage.pk || "",
|
||||||
data: data
|
data: data
|
||||||
});
|
});
|
||||||
|
@ -66,6 +66,7 @@ export class CaptchaStageForm extends Form<CaptchaStage> {
|
||||||
<ak-form-element-horizontal
|
<ak-form-element-horizontal
|
||||||
label=${t`Private Key`}
|
label=${t`Private Key`}
|
||||||
?required=${true}
|
?required=${true}
|
||||||
|
?writeOnly=${true}
|
||||||
name="privateKey">
|
name="privateKey">
|
||||||
<input type="text" value="${ifDefined(this.stage?.privateKey || "")}" class="pf-c-form-control" required>
|
<input type="text" value="${ifDefined(this.stage?.privateKey || "")}" class="pf-c-form-control" required>
|
||||||
<p class="pf-c-form__helper-text">${t`Private key, acquired from https://www.google.com/recaptcha/intro/v3.html.`}</p>
|
<p class="pf-c-form__helper-text">${t`Private key, acquired from https://www.google.com/recaptcha/intro/v3.html.`}</p>
|
||||||
|
|
|
@ -37,7 +37,7 @@ export class EmailStageForm extends Form<EmailStage> {
|
||||||
|
|
||||||
send = (data: EmailStage): Promise<EmailStage> => {
|
send = (data: EmailStage): Promise<EmailStage> => {
|
||||||
if (this.stage) {
|
if (this.stage) {
|
||||||
return new StagesApi(DEFAULT_CONFIG).stagesEmailUpdate({
|
return new StagesApi(DEFAULT_CONFIG).stagesEmailPartialUpdate({
|
||||||
stageUuid: this.stage.pk || "",
|
stageUuid: this.stage.pk || "",
|
||||||
data: data
|
data: data
|
||||||
});
|
});
|
||||||
|
@ -78,6 +78,7 @@ export class EmailStageForm extends Form<EmailStage> {
|
||||||
<ak-form-element-horizontal
|
<ak-form-element-horizontal
|
||||||
label=${t`SMTP Password`}
|
label=${t`SMTP Password`}
|
||||||
?required=${true}
|
?required=${true}
|
||||||
|
?writeOnly=${true}
|
||||||
name="password">
|
name="password">
|
||||||
<input type="text" value="${ifDefined(this.stage?.password || "")}" class="pf-c-form-control" required>
|
<input type="text" value="${ifDefined(this.stage?.password || "")}" class="pf-c-form-control" required>
|
||||||
</ak-form-element-horizontal>
|
</ak-form-element-horizontal>
|
||||||
|
|
Reference in New Issue