2021-05-01 14:55:58 +02:00
|
|
|
import { useEffect, memo } from "react";
|
|
|
|
import { Template } from "./Template";
|
|
|
|
import type { KcProps } from "./KcProps";
|
2021-06-23 08:16:51 +02:00
|
|
|
import type { KcContextBase } from "../getKcContext/KcContextBase";
|
2021-05-01 14:55:58 +02:00
|
|
|
import { useKcMessage } from "../i18n/useKcMessage";
|
|
|
|
import { appendHead } from "../tools/appendHead";
|
|
|
|
import { join as pathJoin } from "path";
|
2021-08-20 17:03:50 +02:00
|
|
|
import { useCssAndCx } from "tss-react";
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
export const LoginOtp = memo(
|
|
|
|
({
|
|
|
|
kcContext,
|
|
|
|
...props
|
|
|
|
}: { kcContext: KcContextBase.LoginOtp } & KcProps) => {
|
|
|
|
const { otpLogin, url } = kcContext;
|
2021-08-20 17:03:50 +02:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
const { cx } = useCssAndCx();
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
const { msg, msgStr } = useKcMessage();
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
useEffect(() => {
|
2021-05-01 14:55:58 +02:00
|
|
|
let isCleanedUp = false;
|
|
|
|
|
|
|
|
appendHead({
|
|
|
|
"type": "javascript",
|
|
|
|
"src": pathJoin(
|
|
|
|
kcContext.url.resourcesCommonPath,
|
2021-10-11 21:35:40 +02:00
|
|
|
"node_modules/jquery/dist/jquery.min.js",
|
|
|
|
),
|
2021-05-01 14:55:58 +02:00
|
|
|
}).then(() => {
|
|
|
|
if (isCleanedUp) return;
|
|
|
|
|
|
|
|
evaluateInlineScript();
|
|
|
|
});
|
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
return () => {
|
|
|
|
isCleanedUp = true;
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Template
|
|
|
|
{...{ kcContext, ...props }}
|
|
|
|
doFetchDefaultThemeResources={true}
|
|
|
|
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-05-01 14:55:58 +02:00
|
|
|
</div>
|
2021-10-11 21:35:40 +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-05-01 14:55:58 +02:00
|
|
|
</div>
|
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
<div className={cx(props.kcInputWrapperClass)}>
|
|
|
|
<input
|
|
|
|
id="otp"
|
|
|
|
name="otp"
|
|
|
|
autoComplete="off"
|
|
|
|
type="text"
|
|
|
|
className={cx(props.kcInputClass)}
|
|
|
|
autoFocus
|
|
|
|
/>
|
|
|
|
</div>
|
2021-05-01 14:55:58 +02:00
|
|
|
</div>
|
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
<div className={cx(props.kcFormGroupClass)}>
|
|
|
|
<div
|
|
|
|
id="kc-form-options"
|
|
|
|
className={cx(props.kcFormOptionsClass)}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={cx(
|
|
|
|
props.kcFormOptionsWrapperClass,
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-05-01 14:55:58 +02:00
|
|
|
|
2021-10-11 21:35:40 +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-05-01 14:55:58 +02:00
|
|
|
</div>
|
2021-10-11 21:35:40 +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
|
|
|
}
|