2021-03-30 20:46:49 +00:00
|
|
|
import { CoreApi, Token } from "authentik-api";
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-05-11 10:44:50 +00:00
|
|
|
import { customElement } from "lit-element";
|
2021-03-30 20:46:49 +00:00
|
|
|
import { html, TemplateResult } from "lit-html";
|
|
|
|
import { DEFAULT_CONFIG } from "../../../api/Config";
|
|
|
|
import { ifDefined } from "lit-html/directives/if-defined";
|
|
|
|
import "../../../elements/forms/HorizontalFormElement";
|
2021-05-11 10:44:50 +00:00
|
|
|
import { ModelForm } from "../../../elements/forms/ModelForm";
|
2021-03-30 20:46:49 +00:00
|
|
|
|
|
|
|
@customElement("ak-user-token-form")
|
2021-05-11 10:44:50 +00:00
|
|
|
export class UserTokenForm extends ModelForm<Token, string> {
|
2021-03-30 20:46:49 +00:00
|
|
|
|
2021-05-11 10:44:50 +00:00
|
|
|
loadInstance(pk: string): Promise<Token> {
|
2021-05-16 12:43:42 +00:00
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreTokensRetrieve({
|
2021-05-11 10:44:50 +00:00
|
|
|
identifier: pk
|
|
|
|
});
|
|
|
|
}
|
2021-03-30 20:46:49 +00:00
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-05-11 10:44:50 +00:00
|
|
|
if (this.instance) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully updated token.`;
|
2021-03-30 20:46:49 +00:00
|
|
|
} else {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully created token.`;
|
2021-03-30 20:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: Token): Promise<Token> => {
|
2021-05-11 10:44:50 +00:00
|
|
|
if (this.instance) {
|
2021-03-30 20:46:49 +00:00
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreTokensUpdate({
|
2021-05-11 10:44:50 +00:00
|
|
|
identifier: this.instance.identifier,
|
2021-05-16 16:24:15 +00:00
|
|
|
tokenRequest: data
|
2021-03-30 20:46:49 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreTokensCreate({
|
2021-05-16 16:24:15 +00:00
|
|
|
tokenRequest: data
|
2021-03-30 20:46:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Identifier`}
|
2021-03-30 20:46:49 +00:00
|
|
|
?required=${true}
|
|
|
|
name="identifier">
|
2021-05-11 10:44:50 +00:00
|
|
|
<input type="text" value="${ifDefined(this.instance?.identifier)}" class="pf-c-form-control" required>
|
2021-03-30 20:46:49 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Description`}
|
2021-03-30 20:46:49 +00:00
|
|
|
name="description">
|
2021-07-14 18:57:16 +00:00
|
|
|
<input type="text" value="${ifDefined(this.instance?.description)}" class="pf-c-form-control">
|
2021-03-30 20:46:49 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|