2022-07-30 00:42:07 +02:00
|
|
|
import React, { useEffect, memo } from "react";
|
2022-07-29 01:31:55 +02:00
|
|
|
import Template from "./Template";
|
2021-05-01 14:55:58 +02:00
|
|
|
import type { KcProps } from "./KcProps";
|
2021-06-23 08:16:51 +02:00
|
|
|
import type { KcContextBase } from "../getKcContext/KcContextBase";
|
2021-10-25 21:26:08 +02:00
|
|
|
import { headInsert } from "../tools/headInsert";
|
2022-07-29 23:10:35 +02:00
|
|
|
import { pathJoin } from "../../bin/tools/pathJoin";
|
2022-09-01 15:13:24 +02:00
|
|
|
import { useCssAndCx } from "../tools/useCssAndCx";
|
2022-07-31 22:30:32 +02:00
|
|
|
import type { I18n } from "../i18n";
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
const LoginOtp = memo(
|
|
|
|
({
|
|
|
|
kcContext,
|
|
|
|
i18n,
|
|
|
|
doFetchDefaultThemeResources = true,
|
|
|
|
...props
|
|
|
|
}: { kcContext: KcContextBase.LoginOtp; i18n: I18n; doFetchDefaultThemeResources?: boolean } & KcProps) => {
|
|
|
|
const { otpLogin, url } = kcContext;
|
2021-08-20 17:03:50 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
const { cx } = useCssAndCx();
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
const { msg, msgStr } = i18n;
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
useEffect(() => {
|
|
|
|
let isCleanedUp = false;
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
headInsert({
|
|
|
|
"type": "javascript",
|
|
|
|
"src": pathJoin(kcContext.url.resourcesCommonPath, "node_modules/jquery/dist/jquery.min.js")
|
|
|
|
}).then(() => {
|
|
|
|
if (isCleanedUp) return;
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
evaluateInlineScript();
|
|
|
|
});
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
return () => {
|
|
|
|
isCleanedUp = true;
|
|
|
|
};
|
|
|
|
}, []);
|
2021-10-11 21:35:40 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
return (
|
|
|
|
<Template
|
|
|
|
{...{ kcContext, i18n, doFetchDefaultThemeResources, ...props }}
|
|
|
|
headerNode={msg("doLogIn")}
|
|
|
|
formNode={
|
|
|
|
<form id="kc-otp-login-form" className={cx(props.kcFormClass)} action={url.loginAction} method="post">
|
|
|
|
{otpLogin.userOtpCredentials.length > 1 && (
|
|
|
|
<div className={cx(props.kcFormGroupClass)}>
|
|
|
|
<div className={cx(props.kcInputWrapperClass)}>
|
|
|
|
{otpLogin.userOtpCredentials.map(otpCredential => (
|
|
|
|
<div key={otpCredential.id} className={cx(props.kcSelectOTPListClass)}>
|
|
|
|
<input type="hidden" value="${otpCredential.id}" />
|
|
|
|
<div className={cx(props.kcSelectOTPListItemClass)}>
|
|
|
|
<span className={cx(props.kcAuthenticatorOtpCircleClass)} />
|
|
|
|
<h2 className={cx(props.kcSelectOTPItemHeadingClass)}>{otpCredential.userLabel}</h2>
|
|
|
|
</div>
|
2021-10-12 00:26:29 +02:00
|
|
|
</div>
|
2022-09-27 21:30:33 +02:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div className={cx(props.kcFormGroupClass)}>
|
|
|
|
<div className={cx(props.kcLabelWrapperClass)}>
|
|
|
|
<label htmlFor="otp" className={cx(props.kcLabelClass)}>
|
|
|
|
{msg("loginOtpOneTime")}
|
|
|
|
</label>
|
2021-10-11 21:35:40 +02:00
|
|
|
</div>
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
<div className={cx(props.kcInputWrapperClass)}>
|
|
|
|
<input id="otp" name="otp" autoComplete="off" type="text" className={cx(props.kcInputClass)} autoFocus />
|
|
|
|
</div>
|
2021-10-12 00:26:29 +02:00
|
|
|
</div>
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
<div className={cx(props.kcFormGroupClass)}>
|
|
|
|
<div id="kc-form-options" className={cx(props.kcFormOptionsClass)}>
|
|
|
|
<div className={cx(props.kcFormOptionsWrapperClass)} />
|
|
|
|
</div>
|
2021-10-12 00:26:29 +02:00
|
|
|
|
2022-09-27 21:30:33 +02:00
|
|
|
<div id="kc-form-buttons" className={cx(props.kcFormButtonsClass)}>
|
|
|
|
<input
|
|
|
|
className={cx(
|
|
|
|
props.kcButtonClass,
|
|
|
|
props.kcButtonPrimaryClass,
|
|
|
|
props.kcButtonBlockClass,
|
|
|
|
props.kcButtonLargeClass
|
|
|
|
)}
|
|
|
|
name="login"
|
|
|
|
id="kc-login"
|
|
|
|
type="submit"
|
|
|
|
value={msgStr("doLogIn")}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-10-12 00:26:29 +02:00
|
|
|
</div>
|
2022-09-27 21:30:33 +02:00
|
|
|
</form>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2021-05-01 14:55:58 +02:00
|
|
|
|
|
|
|
declare const $: any;
|
|
|
|
|
|
|
|
function evaluateInlineScript() {
|
|
|
|
$(document).ready(function () {
|
|
|
|
// Card Single Select
|
2021-10-11 21:35:40 +02:00
|
|
|
$(".card-pf-view-single-select").click(function (this: any) {
|
|
|
|
if ($(this).hasClass("active")) {
|
|
|
|
$(this).removeClass("active");
|
|
|
|
$(this).children().removeAttr("name");
|
|
|
|
} else {
|
|
|
|
$(".card-pf-view-single-select").removeClass("active");
|
|
|
|
$(".card-pf-view-single-select").children().removeAttr("name");
|
|
|
|
$(this).addClass("active");
|
|
|
|
$(this).children().attr("name", "selectedCredentialId");
|
2021-05-01 14:55:58 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
var defaultCred = $(".card-pf-view-single-select")[0];
|
2021-05-01 14:55:58 +02:00
|
|
|
if (defaultCred) {
|
|
|
|
defaultCred.click();
|
|
|
|
}
|
|
|
|
});
|
2021-10-11 21:35:40 +02:00
|
|
|
}
|
2022-07-29 01:31:55 +02:00
|
|
|
|
|
|
|
export default LoginOtp;
|