import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { dateTimeLocal } from "@goauthentik/common/utils"; import { Form } from "@goauthentik/elements/forms/Form"; import "@goauthentik/elements/forms/HorizontalFormElement"; import { ModalForm } from "@goauthentik/elements/forms/ModalForm"; import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { CoreApi, UserServiceAccountRequest, UserServiceAccountResponse } from "@goauthentik/api"; @customElement("ak-user-service-account") export class ServiceAccountForm extends Form { @property({ attribute: false }) result?: UserServiceAccountResponse; getSuccessMessage(): string { return t`Successfully created user.`; } send = async (data: UserServiceAccountRequest): Promise => { const result = await new CoreApi(DEFAULT_CONFIG).coreUsersServiceAccountCreate({ userServiceAccountRequest: data, }); this.result = result; (this.parentElement as ModalForm).showSubmitButton = false; return result; }; resetForm(): void { super.resetForm(); this.result = undefined; } renderRequestForm(): TemplateResult { return html`

${t`User's primary identifier. 150 characters or fewer.`}

${t`Enabling this toggle will create a group named after the user, with the user as member.`}

${t`If this is selected, the token will expire. Upon expiration, the token will be rotated.`}

`; } renderResponseForm(): TemplateResult { return html`

${t`Use the username and password below to authenticate. The password can be retrieved later on the Tokens page.`}

${t`Valid for 360 days, after which the password will automatically rotate. You can copy the password from the Token List.`}

`; } renderForm(): TemplateResult { if (this.result) { return this.renderResponseForm(); } return this.renderRequestForm(); } }