2021-03-02 23:48:31 +01:00
|
|
|
import { useState, memo } from "react";
|
|
|
|
import { Template } from "./Template";
|
2021-03-06 14:42:56 +01:00
|
|
|
import type { KcProps } from "./KcProps";
|
2021-06-23 08:16:51 +02:00
|
|
|
import type { KcContextBase } from "../getKcContext/KcContextBase";
|
2021-03-07 15:37:37 +01:00
|
|
|
import { useKcMessage } from "../i18n/useKcMessage";
|
2021-08-20 17:03:50 +02:00
|
|
|
import { useCssAndCx } from "tss-react";
|
2021-07-21 22:10:28 +02:00
|
|
|
import { useConstCallback } from "powerhooks/useConstCallback";
|
2021-03-02 23:48:31 +01:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
export const Login = memo(
|
|
|
|
({ kcContext, ...props }: { kcContext: KcContextBase.Login } & KcProps) => {
|
|
|
|
const {
|
|
|
|
social,
|
|
|
|
realm,
|
|
|
|
url,
|
|
|
|
usernameEditDisabled,
|
|
|
|
login,
|
|
|
|
auth,
|
|
|
|
registrationDisabled,
|
|
|
|
} = kcContext;
|
2021-03-02 23:48:31 +01:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
const { msg, msgStr } = useKcMessage();
|
2021-08-20 17:03:50 +02:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
const { cx } = useCssAndCx();
|
2021-08-20 17:03:50 +02:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
const [isLoginButtonDisabled, setIsLoginButtonDisabled] =
|
|
|
|
useState(false);
|
2021-03-02 23:48:31 +01:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
const onSubmit = useConstCallback(
|
|
|
|
() => (setIsLoginButtonDisabled(true), true),
|
|
|
|
);
|
2021-03-02 23:48:31 +01:00
|
|
|
|
2021-10-11 21:35:40 +02:00
|
|
|
return (
|
|
|
|
<Template
|
|
|
|
{...{ kcContext, ...props }}
|
|
|
|
doFetchDefaultThemeResources={true}
|
|
|
|
displayInfo={social.displayInfo}
|
|
|
|
displayWide={realm.password && social.providers !== undefined}
|
|
|
|
headerNode={msg("doLogIn")}
|
|
|
|
formNode={
|
2021-03-02 23:48:31 +01:00
|
|
|
<div
|
2021-10-11 21:35:40 +02:00
|
|
|
id="kc-form"
|
|
|
|
className={cx(
|
2021-03-02 23:48:31 +01:00
|
|
|
realm.password &&
|
2021-10-11 21:35:40 +02:00
|
|
|
social.providers !== undefined &&
|
|
|
|
props.kcContentWrapperClass,
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
id="kc-form-wrapper"
|
|
|
|
className={cx(
|
|
|
|
realm.password &&
|
|
|
|
social.providers && [
|
|
|
|
props.kcFormSocialAccountContentClass,
|
|
|
|
props.kcFormSocialAccountClass,
|
|
|
|
],
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{realm.password && (
|
|
|
|
<form
|
|
|
|
id="kc-form-login"
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
action={url.loginAction}
|
|
|
|
method="post"
|
|
|
|
>
|
2021-03-06 14:42:56 +01:00
|
|
|
<div className={cx(props.kcFormGroupClass)}>
|
2021-10-11 21:35:40 +02:00
|
|
|
<label
|
|
|
|
htmlFor="username"
|
|
|
|
className={cx(props.kcLabelClass)}
|
|
|
|
>
|
|
|
|
{!realm.loginWithEmailAllowed
|
|
|
|
? msg("username")
|
|
|
|
: !realm.registrationEmailAsUsername
|
|
|
|
? msg("usernameOrEmail")
|
|
|
|
: msg("email")}
|
2021-03-02 23:48:31 +01:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
tabIndex={1}
|
|
|
|
id="username"
|
2021-03-06 14:42:56 +01:00
|
|
|
className={cx(props.kcInputClass)}
|
2021-03-02 23:48:31 +01:00
|
|
|
name="username"
|
2021-10-11 21:35:40 +02:00
|
|
|
defaultValue={login.username ?? ""}
|
2021-03-02 23:48:31 +01:00
|
|
|
type="text"
|
2021-10-11 21:35:40 +02:00
|
|
|
{...(usernameEditDisabled
|
|
|
|
? { "disabled": true }
|
|
|
|
: {
|
|
|
|
"autoFocus": true,
|
|
|
|
"autoComplete": "off",
|
|
|
|
})}
|
2021-03-02 23:48:31 +01:00
|
|
|
/>
|
|
|
|
</div>
|
2021-03-06 14:42:56 +01:00
|
|
|
<div className={cx(props.kcFormGroupClass)}>
|
2021-10-11 21:35:40 +02:00
|
|
|
<label
|
|
|
|
htmlFor="password"
|
|
|
|
className={cx(props.kcLabelClass)}
|
|
|
|
>
|
2021-03-07 15:37:37 +01:00
|
|
|
{msg("password")}
|
2021-03-02 23:48:31 +01:00
|
|
|
</label>
|
2021-10-11 21:35:40 +02:00
|
|
|
<input
|
|
|
|
tabIndex={2}
|
|
|
|
id="password"
|
|
|
|
className={cx(props.kcInputClass)}
|
|
|
|
name="password"
|
|
|
|
type="password"
|
|
|
|
autoComplete="off"
|
|
|
|
/>
|
2021-03-02 23:48:31 +01:00
|
|
|
</div>
|
2021-10-11 21:35:40 +02:00
|
|
|
<div
|
|
|
|
className={cx(
|
|
|
|
props.kcFormGroupClass,
|
|
|
|
props.kcFormSettingClass,
|
|
|
|
)}
|
|
|
|
>
|
2021-03-02 23:48:31 +01:00
|
|
|
<div id="kc-form-options">
|
2021-10-11 21:35:40 +02:00
|
|
|
{realm.rememberMe &&
|
|
|
|
!usernameEditDisabled && (
|
|
|
|
<div className="checkbox">
|
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
tabIndex={3}
|
|
|
|
id="rememberMe"
|
|
|
|
name="rememberMe"
|
|
|
|
type="checkbox"
|
|
|
|
{...(login.rememberMe
|
|
|
|
? {
|
|
|
|
"checked":
|
|
|
|
true,
|
|
|
|
}
|
|
|
|
: {})}
|
|
|
|
/>
|
|
|
|
{msg("rememberMe")}
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
)}
|
2021-03-02 23:48:31 +01:00
|
|
|
</div>
|
2021-10-11 21:35:40 +02:00
|
|
|
<div
|
|
|
|
className={cx(
|
|
|
|
props.kcFormOptionsWrapperClass,
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{realm.resetPasswordAllowed && (
|
2021-03-02 23:48:31 +01:00
|
|
|
<span>
|
2021-10-11 21:35:40 +02:00
|
|
|
<a
|
|
|
|
tabIndex={5}
|
|
|
|
href={
|
|
|
|
url.loginResetCredentialsUrl
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{msg(
|
|
|
|
"doForgotPassword",
|
|
|
|
)}
|
|
|
|
</a>
|
2021-03-02 23:48:31 +01:00
|
|
|
</span>
|
2021-10-11 21:35:40 +02:00
|
|
|
)}
|
2021-03-02 23:48:31 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-11 21:35:40 +02:00
|
|
|
<div
|
|
|
|
id="kc-form-buttons"
|
|
|
|
className={cx(props.kcFormGroupClass)}
|
|
|
|
>
|
2021-03-02 23:48:31 +01:00
|
|
|
<input
|
|
|
|
type="hidden"
|
|
|
|
id="id-hidden-input"
|
|
|
|
name="credentialId"
|
2021-10-11 21:35:40 +02:00
|
|
|
{...(auth?.selectedCredential !==
|
|
|
|
undefined
|
|
|
|
? {
|
|
|
|
"value":
|
|
|
|
auth.selectedCredential,
|
|
|
|
}
|
|
|
|
: {})}
|
2021-03-02 23:48:31 +01:00
|
|
|
/>
|
|
|
|
<input
|
|
|
|
tabIndex={4}
|
2021-10-11 21:35:40 +02:00
|
|
|
className={cx(
|
|
|
|
props.kcButtonClass,
|
|
|
|
props.kcButtonPrimaryClass,
|
|
|
|
props.kcButtonBlockClass,
|
|
|
|
props.kcButtonLargeClass,
|
|
|
|
)}
|
|
|
|
name="login"
|
|
|
|
id="kc-login"
|
|
|
|
type="submit"
|
2021-03-07 15:37:37 +01:00
|
|
|
value={msgStr("doLogIn")}
|
2021-03-02 23:48:31 +01:00
|
|
|
disabled={isLoginButtonDisabled}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</form>
|
2021-10-11 21:35:40 +02:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
{realm.password && social.providers !== undefined && (
|
|
|
|
<div
|
|
|
|
id="kc-social-providers"
|
|
|
|
className={cx(
|
|
|
|
props.kcFormSocialAccountContentClass,
|
|
|
|
props.kcFormSocialAccountClass,
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<ul
|
|
|
|
className={cx(
|
|
|
|
props.kcFormSocialAccountListClass,
|
|
|
|
social.providers.length > 4 &&
|
|
|
|
props.kcFormSocialAccountDoubleListClass,
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{social.providers.map(p => (
|
|
|
|
<li
|
|
|
|
key={p.providerId}
|
|
|
|
className={cx(
|
|
|
|
props.kcFormSocialAccountListLinkClass,
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<a
|
|
|
|
href={p.loginUrl}
|
|
|
|
id={`zocial-${p.alias}`}
|
|
|
|
className={cx(
|
|
|
|
"zocial",
|
|
|
|
p.providerId,
|
|
|
|
)}
|
|
|
|
>
|
2021-03-02 23:48:31 +01:00
|
|
|
<span>{p.displayName}</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
2021-10-11 21:35:40 +02:00
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
infoNode={
|
2021-03-02 23:48:31 +01:00
|
|
|
realm.password &&
|
2021-03-04 23:24:43 +01:00
|
|
|
realm.registrationAllowed &&
|
2021-10-11 21:35:40 +02:00
|
|
|
!registrationDisabled && (
|
|
|
|
<div id="kc-registration">
|
|
|
|
<span>
|
|
|
|
{msg("noAccount")}
|
|
|
|
<a tabIndex={6} href={url.registrationUrl}>
|
|
|
|
{msg("doRegister")}
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|