2024-05-11 01:13:09 +02:00
|
|
|
import { Fragment } from "react";
|
2024-06-09 08:27:07 +02:00
|
|
|
import { getKcClsx } from "keycloakify/login/lib/kcClsx";
|
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";
|
2022-10-13 11:58:31 +02:00
|
|
|
|
2024-06-09 11:20:45 +02:00
|
|
|
export default function LoginOtp(props: PageProps<Extract<KcContext, { pageId: "login-otp.ftl" }>, I18n>) {
|
|
|
|
const { kcContext, i18n, doUseDefaultCss, Template, classes } = props;
|
2023-03-18 06:14:05 +01:00
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
const { kcClsx } = getKcClsx({
|
2023-03-21 05:27:31 +01:00
|
|
|
doUseDefaultCss,
|
2023-03-18 06:14:05 +01:00
|
|
|
classes
|
|
|
|
});
|
2022-10-13 11:58:31 +02:00
|
|
|
|
2024-05-11 01:13:09 +02:00
|
|
|
const { otpLogin, url, messagesPerField } = kcContext;
|
2022-10-13 11:58:31 +02:00
|
|
|
|
2024-06-09 11:20:45 +02:00
|
|
|
const { msg, msgStr } = i18n;
|
2022-10-13 11:58:31 +02:00
|
|
|
|
|
|
|
return (
|
2024-06-09 08:27:07 +02:00
|
|
|
<Template
|
|
|
|
kcContext={kcContext}
|
2024-06-09 11:20:45 +02:00
|
|
|
i18n={i18n}
|
2024-06-09 08:27:07 +02:00
|
|
|
doUseDefaultCss={doUseDefaultCss}
|
|
|
|
classes={classes}
|
|
|
|
displayMessage={!messagesPerField.existsError("totp")}
|
|
|
|
headerNode={msg("doLogIn")}
|
|
|
|
>
|
|
|
|
<form id="kc-otp-login-form" className={kcClsx("kcFormClass")} action={url.loginAction} method="post">
|
2024-05-11 01:13:09 +02:00
|
|
|
{otpLogin.userOtpCredentials.length > 1 && (
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={kcClsx("kcFormGroupClass")}>
|
|
|
|
<div className={kcClsx("kcInputWrapperClass")}>
|
2024-05-11 01:13:09 +02:00
|
|
|
{otpLogin.userOtpCredentials.map((otpCredential, index) => (
|
|
|
|
<Fragment key={index}>
|
|
|
|
<input
|
|
|
|
id={`kc-otp-credential-${index}`}
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcLoginOTPListInputClass")}
|
2024-05-11 01:13:09 +02:00
|
|
|
type="radio"
|
|
|
|
name="selectedCredentialId"
|
|
|
|
value={otpCredential.id}
|
|
|
|
defaultChecked={otpCredential.id === otpLogin.selectedCredentialId}
|
|
|
|
/>
|
2024-06-09 08:27:07 +02:00
|
|
|
<label htmlFor={`kc-otp-credential-${index}`} className={kcClsx("kcLoginOTPListClass")} tabIndex={index}>
|
|
|
|
<span className={kcClsx("kcLoginOTPListItemHeaderClass")}>
|
|
|
|
<span className={kcClsx("kcLoginOTPListItemIconBodyClass")}>
|
|
|
|
<i className={kcClsx("kcLoginOTPListItemIconClass")} aria-hidden="true"></i>
|
2024-05-11 01:13:09 +02:00
|
|
|
</span>
|
2024-06-09 08:27:07 +02:00
|
|
|
<span className={kcClsx("kcLoginOTPListItemTitleClass")}>{otpCredential.userLabel}</span>
|
2024-05-11 01:13:09 +02:00
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
</Fragment>
|
|
|
|
))}
|
2024-02-02 14:35:14 +02:00
|
|
|
</div>
|
2023-03-21 02:36:13 +01:00
|
|
|
</div>
|
2024-05-11 01:13:09 +02:00
|
|
|
)}
|
2021-10-12 00:26:29 +02:00
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={kcClsx("kcFormGroupClass")}>
|
|
|
|
<div className={kcClsx("kcLabelWrapperClass")}>
|
|
|
|
<label htmlFor="otp" className={kcClsx("kcLabelClass")}>
|
2024-05-11 01:13:09 +02:00
|
|
|
{msg("loginOtpOneTime")}
|
|
|
|
</label>
|
|
|
|
</div>
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={kcClsx("kcInputWrapperClass")}>
|
2024-05-11 01:13:09 +02:00
|
|
|
<input
|
|
|
|
id="otp"
|
|
|
|
name="otp"
|
|
|
|
autoComplete="off"
|
|
|
|
type="text"
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcInputClass")}
|
2024-05-11 01:13:09 +02:00
|
|
|
autoFocus
|
|
|
|
aria-invalid={messagesPerField.existsError("totp")}
|
|
|
|
/>
|
|
|
|
{messagesPerField.existsError("totp") && (
|
2024-06-09 08:27:07 +02:00
|
|
|
<span id="input-error-otp-code" className={kcClsx("kcInputErrorMessageClass")} aria-live="polite">
|
2024-05-11 01:13:09 +02:00
|
|
|
{messagesPerField.get("totp")}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-03-21 02:36:13 +01:00
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={kcClsx("kcFormGroupClass")}>
|
|
|
|
<div id="kc-form-options" className={kcClsx("kcFormOptionsClass")}>
|
|
|
|
<div className={kcClsx("kcFormOptionsWrapperClass")}></div>
|
2024-05-11 01:13:09 +02:00
|
|
|
</div>
|
2024-06-09 08:27:07 +02:00
|
|
|
<div id="kc-form-buttons" className={kcClsx("kcFormButtonsClass")}>
|
2024-05-11 01:13:09 +02:00
|
|
|
<input
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcButtonClass", "kcButtonPrimaryClass", "kcButtonBlockClass", "kcButtonLargeClass")}
|
2024-05-11 01:13:09 +02:00
|
|
|
name="login"
|
|
|
|
id="kc-login"
|
|
|
|
type="submit"
|
|
|
|
value={msgStr("doLogIn")}
|
|
|
|
/>
|
2023-03-21 02:36:13 +01:00
|
|
|
</div>
|
2024-05-11 01:13:09 +02:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</Template>
|
2022-10-13 11:58:31 +02:00
|
|
|
);
|
2023-02-25 18:11:23 +01:00
|
|
|
}
|