2024-12-09 05:06:47 +01:00
|
|
|
import type { JSX } from "keycloakify/tools/JSX";
|
2024-05-11 01:30:23 +02:00
|
|
|
import { useState, useEffect, useReducer } from "react";
|
2024-09-22 20:41:18 +02:00
|
|
|
import { kcSanitize } from "keycloakify/lib/kcSanitize";
|
2023-03-18 06:14:05 +01:00
|
|
|
import { clsx } from "keycloakify/tools/clsx";
|
2024-06-22 14:10:08 +02:00
|
|
|
import { assert } from "keycloakify/tools/assert";
|
2024-06-09 08:27:07 +02:00
|
|
|
import { getKcClsx, type KcClsx } 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-04 15:01:08 -04:00
|
|
|
|
2024-06-09 11:20:45 +02:00
|
|
|
export default function LoginPassword(props: PageProps<Extract<KcContext, { pageId: "login-password.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-04 15:01:08 -04:00
|
|
|
|
2024-05-11 01:30:23 +02:00
|
|
|
const { realm, url, messagesPerField } = kcContext;
|
2022-10-04 15:01:08 -04:00
|
|
|
|
2022-10-13 11:58:31 +02:00
|
|
|
const { msg, msgStr } = i18n;
|
2022-10-04 15:01:08 -04:00
|
|
|
|
2022-10-13 11:58:31 +02:00
|
|
|
const [isLoginButtonDisabled, setIsLoginButtonDisabled] = useState(false);
|
2022-10-04 15:01:08 -04:00
|
|
|
|
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}
|
|
|
|
headerNode={msg("doLogIn")}
|
|
|
|
displayMessage={!messagesPerField.existsError("password")}
|
|
|
|
>
|
2023-03-21 02:36:13 +01:00
|
|
|
<div id="kc-form">
|
|
|
|
<div id="kc-form-wrapper">
|
2024-05-11 01:30:23 +02:00
|
|
|
<form
|
|
|
|
id="kc-form-login"
|
|
|
|
onSubmit={() => {
|
|
|
|
setIsLoginButtonDisabled(true);
|
|
|
|
return true;
|
|
|
|
}}
|
|
|
|
action={url.loginAction}
|
|
|
|
method="post"
|
|
|
|
>
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={clsx(kcClsx("kcFormGroupClass"), "no-bottom-margin")}>
|
2023-03-21 02:36:13 +01:00
|
|
|
<hr />
|
2024-06-09 08:27:07 +02:00
|
|
|
<label htmlFor="password" className={kcClsx("kcLabelClass")}>
|
2023-03-21 02:36:13 +01:00
|
|
|
{msg("password")}
|
|
|
|
</label>
|
2024-05-11 01:30:23 +02:00
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
<PasswordWrapper kcClsx={kcClsx} i18n={i18n} passwordInputId="password">
|
2024-05-11 01:30:23 +02:00
|
|
|
<input
|
|
|
|
tabIndex={2}
|
|
|
|
id="password"
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcInputClass")}
|
2024-05-11 01:30:23 +02:00
|
|
|
name="password"
|
|
|
|
type="password"
|
|
|
|
autoFocus
|
|
|
|
autoComplete="on"
|
|
|
|
aria-invalid={messagesPerField.existsError("username", "password")}
|
|
|
|
/>
|
|
|
|
</PasswordWrapper>
|
|
|
|
|
|
|
|
{messagesPerField.existsError("password") && (
|
2024-07-04 19:53:57 +02:00
|
|
|
<span
|
|
|
|
id="input-error-password"
|
|
|
|
className={kcClsx("kcInputErrorMessageClass")}
|
|
|
|
aria-live="polite"
|
|
|
|
dangerouslySetInnerHTML={{
|
2024-09-22 20:41:18 +02:00
|
|
|
__html: kcSanitize(messagesPerField.get("password"))
|
2024-07-04 19:53:57 +02:00
|
|
|
}}
|
|
|
|
/>
|
2024-05-11 01:30:23 +02:00
|
|
|
)}
|
2023-03-21 02:36:13 +01:00
|
|
|
</div>
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={kcClsx("kcFormGroupClass", "kcFormSettingClass")}>
|
2023-03-21 02:36:13 +01:00
|
|
|
<div id="kc-form-options" />
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={kcClsx("kcFormOptionsWrapperClass")}>
|
2023-03-21 02:36:13 +01:00
|
|
|
{realm.resetPasswordAllowed && (
|
|
|
|
<span>
|
|
|
|
<a tabIndex={5} href={url.loginResetCredentialsUrl}>
|
|
|
|
{msg("doForgotPassword")}
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
)}
|
2022-10-13 11:58:31 +02:00
|
|
|
</div>
|
2023-03-21 02:36:13 +01:00
|
|
|
</div>
|
2024-06-09 08:27:07 +02:00
|
|
|
<div id="kc-form-buttons" className={kcClsx("kcFormGroupClass")}>
|
2023-03-21 02:36:13 +01:00
|
|
|
<input
|
|
|
|
tabIndex={4}
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcButtonClass", "kcButtonPrimaryClass", "kcButtonBlockClass", "kcButtonLargeClass")}
|
2023-03-21 02:36:13 +01:00
|
|
|
name="login"
|
|
|
|
id="kc-login"
|
|
|
|
type="submit"
|
|
|
|
value={msgStr("doLogIn")}
|
|
|
|
disabled={isLoginButtonDisabled}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</form>
|
2022-10-13 11:58:31 +02:00
|
|
|
</div>
|
2023-03-21 02:36:13 +01:00
|
|
|
</div>
|
|
|
|
</Template>
|
2022-10-13 11:58:31 +02:00
|
|
|
);
|
2023-02-25 18:11:23 +01:00
|
|
|
}
|
2024-05-11 01:30:23 +02:00
|
|
|
|
2024-06-09 08:27:07 +02:00
|
|
|
function PasswordWrapper(props: { kcClsx: KcClsx; i18n: I18n; passwordInputId: string; children: JSX.Element }) {
|
|
|
|
const { kcClsx, i18n, passwordInputId, children } = props;
|
2024-05-11 01:30:23 +02:00
|
|
|
|
|
|
|
const { msgStr } = i18n;
|
|
|
|
|
|
|
|
const [isPasswordRevealed, toggleIsPasswordRevealed] = useReducer((isPasswordRevealed: boolean) => !isPasswordRevealed, false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const passwordInputElement = document.getElementById(passwordInputId);
|
|
|
|
|
|
|
|
assert(passwordInputElement instanceof HTMLInputElement);
|
|
|
|
|
|
|
|
passwordInputElement.type = isPasswordRevealed ? "text" : "password";
|
|
|
|
}, [isPasswordRevealed]);
|
|
|
|
|
|
|
|
return (
|
2024-06-09 08:27:07 +02:00
|
|
|
<div className={kcClsx("kcInputGroup")}>
|
2024-05-11 01:30:23 +02:00
|
|
|
{children}
|
|
|
|
<button
|
|
|
|
type="button"
|
2024-06-09 08:27:07 +02:00
|
|
|
className={kcClsx("kcFormPasswordVisibilityButtonClass")}
|
2024-05-11 01:30:23 +02:00
|
|
|
aria-label={msgStr(isPasswordRevealed ? "hidePassword" : "showPassword")}
|
|
|
|
aria-controls={passwordInputId}
|
|
|
|
onClick={toggleIsPasswordRevealed}
|
|
|
|
>
|
2024-06-09 08:27:07 +02:00
|
|
|
<i className={kcClsx(isPasswordRevealed ? "kcFormPasswordVisibilityIconHide" : "kcFormPasswordVisibilityIconShow")} aria-hidden />
|
2024-05-11 01:30:23 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|