2024-05-11 16:25:12 +02:00
|
|
|
import { clsx } from "keycloakify/tools/clsx";
|
2024-06-09 08:27:07 +02:00
|
|
|
import { getKcClsx, type KcClsx } from "keycloakify/login/lib/kcClsx";
|
2024-09-09 07:39:14 +02:00
|
|
|
import { useScript } from "keycloakify/login/pages/LoginRecoveryAuthnCodeConfig.useScript";
|
2024-06-05 21:13:58 +02:00
|
|
|
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
|
|
|
import type { KcContext } from "../KcContext";
|
2024-06-09 11:20:45 +02:00
|
|
|
import type { I18n } from "../i18n";
|
2024-05-11 16:25:12 +02:00
|
|
|
|
2024-06-09 11:20:45 +02:00
|
|
|
export default function LoginRecoveryAuthnCodeConfig(props: PageProps<Extract<KcContext, { pageId: "login-recovery-authn-code-config.ftl" }>, I18n>) {
|
|
|
|
const { kcContext, i18n, doUseDefaultCss, Template, classes } = props;
|
2024-05-11 16:25:12 +02:00
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
const { kcClsx } = getKcClsx({
|
2024-05-11 16:25:12 +02:00
|
|
|
doUseDefaultCss,
|
|
|
|
classes
|
|
|
|
});
|
|
|
|
|
|
|
|
const { recoveryAuthnCodesConfigBean, isAppInitiatedAction } = kcContext;
|
|
|
|
|
|
|
|
const { msg, msgStr } = i18n;
|
|
|
|
|
2024-09-09 07:39:14 +02:00
|
|
|
const olRecoveryCodesListId = "kc-recovery-codes-list";
|
2024-05-11 16:25:12 +02:00
|
|
|
|
2024-09-09 07:39:14 +02:00
|
|
|
useScript({ olRecoveryCodesListId, i18n });
|
2024-05-11 21:26:30 +02:00
|
|
|
|
2024-05-11 16:25:12 +02:00
|
|
|
return (
|
2024-06-09 11:20:45 +02:00
|
|
|
<Template
|
|
|
|
kcContext={kcContext}
|
|
|
|
i18n={i18n}
|
|
|
|
doUseDefaultCss={doUseDefaultCss}
|
|
|
|
classes={classes}
|
|
|
|
headerNode={msg("recovery-code-config-header")}
|
|
|
|
>
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={clsx("pf-c-alert", "pf-m-warning", "pf-m-inline", kcClsx("kcRecoveryCodesWarning"))} aria-label="Warning alert">
|
2024-05-11 16:25:12 +02:00
|
|
|
<div className="pf-c-alert__icon">
|
|
|
|
<i className="pficon-warning-triangle-o" aria-hidden="true" />
|
|
|
|
</div>
|
|
|
|
<h4 className="pf-c-alert__title">
|
|
|
|
<span className="pf-screen-reader">Warning alert:</span>
|
|
|
|
{msg("recovery-code-config-warning-title")}
|
|
|
|
</h4>
|
|
|
|
<div className="pf-c-alert__description">
|
|
|
|
<p>{msg("recovery-code-config-warning-message")}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-09-09 07:39:14 +02:00
|
|
|
<ol id={olRecoveryCodesListId} className={kcClsx("kcRecoveryCodesList")}>
|
2024-05-11 16:25:12 +02:00
|
|
|
{recoveryAuthnCodesConfigBean.generatedRecoveryAuthnCodesList.map((code, index) => (
|
|
|
|
<li key={index}>
|
|
|
|
<span>{index + 1}:</span> {code.slice(0, 4)}-{code.slice(4, 8)}-{code.slice(8)}
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
{/* actions */}
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={kcClsx("kcRecoveryCodesActions")}>
|
2024-05-11 16:25:12 +02:00
|
|
|
<button id="printRecoveryCodes" className={clsx("pf-c-button", "pf-m-link")} type="button">
|
|
|
|
<i className="pficon-print" aria-hidden="true" /> {msg("recovery-codes-print")}
|
|
|
|
</button>
|
|
|
|
<button id="downloadRecoveryCodes" className={clsx("pf-c-button", "pf-m-link")} type="button">
|
|
|
|
<i className="pficon-save" aria-hidden="true" /> {msg("recovery-codes-download")}
|
|
|
|
</button>
|
|
|
|
<button id="copyRecoveryCodes" className={clsx("pf-c-button", "pf-m-link")} type="button">
|
|
|
|
<i className="pficon-blueprint" aria-hidden="true" /> {msg("recovery-codes-copy")}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* confirmation checkbox */}
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={kcClsx("kcFormOptionsClass")}>
|
2024-05-11 16:25:12 +02:00
|
|
|
<input
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcCheckInputClass")}
|
2024-05-11 16:25:12 +02:00
|
|
|
type="checkbox"
|
|
|
|
id="kcRecoveryCodesConfirmationCheck"
|
|
|
|
name="kcRecoveryCodesConfirmationCheck"
|
2024-11-09 19:50:29 +01:00
|
|
|
onChange={event => {
|
|
|
|
//@ts-expect-error: This is inherited from the original code
|
|
|
|
document.getElementById("saveRecoveryAuthnCodesBtn").disabled = !event.target.checked;
|
2024-05-11 16:25:12 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<label htmlFor="kcRecoveryCodesConfirmationCheck">{msg("recovery-codes-confirmation-message")}</label>
|
|
|
|
</div>
|
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
<form action={kcContext.url.loginAction} className={kcClsx("kcFormGroupClass")} id="kc-recovery-codes-settings-form" method="post">
|
2024-05-11 16:25:12 +02:00
|
|
|
<input type="hidden" name="generatedRecoveryAuthnCodes" value={recoveryAuthnCodesConfigBean.generatedRecoveryAuthnCodesAsString} />
|
|
|
|
<input type="hidden" name="generatedAt" value={recoveryAuthnCodesConfigBean.generatedAt} />
|
|
|
|
<input type="hidden" id="userLabel" name="userLabel" value={msgStr("recovery-codes-label-default")} />
|
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
<LogoutOtherSessions kcClsx={kcClsx} i18n={i18n} />
|
2024-05-11 16:25:12 +02:00
|
|
|
|
|
|
|
{isAppInitiatedAction ? (
|
|
|
|
<>
|
|
|
|
<input
|
|
|
|
type="submit"
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcButtonClass", "kcButtonPrimaryClass", "kcButtonLargeClass")}
|
2024-05-11 16:25:12 +02:00
|
|
|
id="saveRecoveryAuthnCodesBtn"
|
|
|
|
value={msgStr("recovery-codes-action-complete")}
|
|
|
|
disabled
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
type="submit"
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcButtonClass", "kcButtonDefaultClass", "kcButtonLargeClass")}
|
2024-05-11 16:25:12 +02:00
|
|
|
id="cancelRecoveryAuthnCodesBtn"
|
|
|
|
name="cancel-aia"
|
|
|
|
value="true"
|
|
|
|
>
|
|
|
|
{msg("recovery-codes-action-cancel")}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<input
|
|
|
|
type="submit"
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcButtonClass", "kcButtonPrimaryClass", "kcButtonBlockClass", "kcButtonLargeClass")}
|
2024-05-11 16:25:12 +02:00
|
|
|
id="saveRecoveryAuthnCodesBtn"
|
|
|
|
value={msgStr("recovery-codes-action-complete")}
|
|
|
|
disabled
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</form>
|
|
|
|
</Template>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
function LogoutOtherSessions(props: { kcClsx: KcClsx; i18n: I18n }) {
|
|
|
|
const { kcClsx, i18n } = props;
|
2024-05-11 16:25:12 +02:00
|
|
|
|
|
|
|
const { msg } = i18n;
|
|
|
|
|
|
|
|
return (
|
2024-06-09 08:27:07 +02:00
|
|
|
<div id="kc-form-options" className={kcClsx("kcFormOptionsClass")}>
|
|
|
|
<div className={kcClsx("kcFormOptionsWrapperClass")}>
|
2024-05-11 16:25:12 +02:00
|
|
|
<div className="checkbox">
|
|
|
|
<label>
|
|
|
|
<input type="checkbox" id="logout-sessions" name="logout-sessions" value="on" defaultChecked={true} />
|
|
|
|
{msg("logoutOtherSessions")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|