Update login-update-password.ftl page
This commit is contained in:
parent
f228e50443
commit
891d190787
@ -396,7 +396,6 @@ export declare namespace KcContext {
|
|||||||
|
|
||||||
export type LoginUpdatePassword = Common & {
|
export type LoginUpdatePassword = Common & {
|
||||||
pageId: "login-update-password.ftl";
|
pageId: "login-update-password.ftl";
|
||||||
username: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LoginIdpLinkConfirm = Common & {
|
export type LoginIdpLinkConfirm = Common & {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
import { useEffect, useReducer } from "react";
|
||||||
import { clsx } from "keycloakify/tools/clsx";
|
import { clsx } from "keycloakify/tools/clsx";
|
||||||
|
import { assert } from "tsafe/assert";
|
||||||
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
import type { PageProps } from "keycloakify/login/pages/PageProps";
|
||||||
import { useGetClassName } from "keycloakify/login/lib/useGetClassName";
|
import { useGetClassName } from "keycloakify/login/lib/useGetClassName";
|
||||||
import type { KcContext } from "../kcContext";
|
import type { KcContext } from "../kcContext";
|
||||||
@ -14,93 +16,83 @@ export default function LoginUpdatePassword(props: PageProps<Extract<KcContext,
|
|||||||
|
|
||||||
const { msg, msgStr } = i18n;
|
const { msg, msgStr } = i18n;
|
||||||
|
|
||||||
const { url, messagesPerField, isAppInitiatedAction, username } = kcContext;
|
const { url, messagesPerField, isAppInitiatedAction } = kcContext;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Template {...{ kcContext, i18n, doUseDefaultCss, classes }} headerNode={msg("updatePasswordTitle")}>
|
<Template
|
||||||
|
{...{ kcContext, i18n, doUseDefaultCss, classes }}
|
||||||
|
displayMessage={!messagesPerField.existsError("password", "password-confirm")}
|
||||||
|
headerNode={msg("updatePasswordTitle")}
|
||||||
|
>
|
||||||
<form id="kc-passwd-update-form" className={getClassName("kcFormClass")} action={url.loginAction} method="post">
|
<form id="kc-passwd-update-form" className={getClassName("kcFormClass")} action={url.loginAction} method="post">
|
||||||
<input
|
<div className={getClassName("kcFormGroupClass")}>
|
||||||
type="text"
|
|
||||||
id="username"
|
|
||||||
name="username"
|
|
||||||
value={username}
|
|
||||||
readOnly={true}
|
|
||||||
autoComplete="username"
|
|
||||||
style={{ display: "none" }}
|
|
||||||
/>
|
|
||||||
<input type="password" id="password" name="password" autoComplete="current-password" style={{ display: "none" }} />
|
|
||||||
|
|
||||||
<div
|
|
||||||
className={clsx(
|
|
||||||
getClassName("kcFormGroupClass"),
|
|
||||||
messagesPerField.printIfExists("password", getClassName("kcFormGroupErrorClass"))
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className={getClassName("kcLabelWrapperClass")}>
|
<div className={getClassName("kcLabelWrapperClass")}>
|
||||||
<label htmlFor="password-new" className={getClassName("kcLabelClass")}>
|
<label htmlFor="password-new" className={getClassName("kcLabelClass")}>
|
||||||
{msg("passwordNew")}
|
{msg("passwordNew")}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
<div className={getClassName("kcInputWrapperClass")}>
|
||||||
<div className={getClassName("kcInputWrapperClass")}>
|
<PasswordWrapper {...{ getClassName, i18n }} passwordInputId="password-new">
|
||||||
<input
|
<input
|
||||||
type="password"
|
type="password"
|
||||||
id="password-new"
|
id="password-new"
|
||||||
name="password-new"
|
name="password-new"
|
||||||
autoFocus
|
className={getClassName("kcInputClass")}
|
||||||
autoComplete="new-password"
|
autoFocus
|
||||||
className={getClassName("kcInputClass")}
|
autoComplete="new-password"
|
||||||
/>
|
aria-invalid={messagesPerField.existsError("password", "password-confirm")}
|
||||||
|
/>
|
||||||
|
</PasswordWrapper>
|
||||||
|
|
||||||
|
{messagesPerField.existsError("password") && (
|
||||||
|
<span id="input-error-password" className={getClassName("kcInputErrorMessageClass")} aria-live="polite">
|
||||||
|
{messagesPerField.get("password")}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div className={getClassName("kcFormGroupClass")}>
|
||||||
className={clsx(
|
|
||||||
getClassName("kcFormGroupClass"),
|
|
||||||
messagesPerField.printIfExists("password-confirm", getClassName("kcFormGroupErrorClass"))
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className={getClassName("kcLabelWrapperClass")}>
|
<div className={getClassName("kcLabelWrapperClass")}>
|
||||||
<label htmlFor="password-confirm" className={getClassName("kcLabelClass")}>
|
<label htmlFor="password-confirm" className={getClassName("kcLabelClass")}>
|
||||||
{msg("passwordConfirm")}
|
{msg("passwordConfirm")}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div className={getClassName("kcInputWrapperClass")}>
|
<div className={getClassName("kcInputWrapperClass")}>
|
||||||
<input
|
<PasswordWrapper {...{ getClassName, i18n }} passwordInputId="password-confirm">
|
||||||
type="password"
|
<input
|
||||||
id="password-confirm"
|
type="password"
|
||||||
name="password-confirm"
|
id="password-confirm"
|
||||||
autoComplete="new-password"
|
name="password-confirm"
|
||||||
className={getClassName("kcInputClass")}
|
className={getClassName("kcInputClass")}
|
||||||
/>
|
autoFocus
|
||||||
</div>
|
autoComplete="new-password"
|
||||||
</div>
|
aria-invalid={messagesPerField.existsError("password", "password-confirm")}
|
||||||
|
/>
|
||||||
|
</PasswordWrapper>
|
||||||
|
|
||||||
<div className={getClassName("kcFormGroupClass")}>
|
{messagesPerField.existsError("password-confirm") && (
|
||||||
<div id="kc-form-options" className={getClassName("kcFormOptionsClass")}>
|
<span id="input-error-password-confirm" className={getClassName("kcInputErrorMessageClass")} aria-live="polite">
|
||||||
<div className={getClassName("kcFormOptionsWrapperClass")}>
|
{messagesPerField.get("password-confirm")}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={getClassName("kcFormGroupClass")}>
|
||||||
|
<LogoutOtherSessions {...{ getClassName, i18n }} />
|
||||||
|
|
||||||
|
<div id="kc-form-buttons" className={getClassName("kcFormButtonsClass")}>
|
||||||
|
<input
|
||||||
|
className={clsx(
|
||||||
|
getClassName("kcButtonClass"),
|
||||||
|
getClassName("kcButtonPrimaryClass"),
|
||||||
|
isAppInitiatedAction && getClassName("kcButtonBlockClass"),
|
||||||
|
getClassName("kcButtonLargeClass")
|
||||||
|
)}
|
||||||
|
type="submit"
|
||||||
|
value={msgStr("doSubmit")}
|
||||||
|
/>
|
||||||
{isAppInitiatedAction && (
|
{isAppInitiatedAction && (
|
||||||
<div className="checkbox">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" id="logout-sessions" name="logout-sessions" value="on" checked />
|
|
||||||
{msgStr("logoutOtherSessions")}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="kc-form-buttons" className={getClassName("kcFormButtonsClass")}>
|
|
||||||
{isAppInitiatedAction ? (
|
|
||||||
<>
|
|
||||||
<input
|
|
||||||
className={clsx(
|
|
||||||
getClassName("kcButtonClass"),
|
|
||||||
getClassName("kcButtonPrimaryClass"),
|
|
||||||
getClassName("kcButtonLargeClass")
|
|
||||||
)}
|
|
||||||
type="submit"
|
|
||||||
defaultValue={msgStr("doSubmit")}
|
|
||||||
/>
|
|
||||||
<button
|
<button
|
||||||
className={clsx(
|
className={clsx(
|
||||||
getClassName("kcButtonClass"),
|
getClassName("kcButtonClass"),
|
||||||
@ -113,22 +105,69 @@ export default function LoginUpdatePassword(props: PageProps<Extract<KcContext,
|
|||||||
>
|
>
|
||||||
{msg("doCancel")}
|
{msg("doCancel")}
|
||||||
</button>
|
</button>
|
||||||
</>
|
)}
|
||||||
) : (
|
</div>
|
||||||
<input
|
|
||||||
className={clsx(
|
|
||||||
getClassName("kcButtonClass"),
|
|
||||||
getClassName("kcButtonPrimaryClass"),
|
|
||||||
getClassName("kcButtonBlockClass"),
|
|
||||||
getClassName("kcButtonLargeClass")
|
|
||||||
)}
|
|
||||||
type="submit"
|
|
||||||
value={msgStr("doSubmit")}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Template>
|
</Template>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function LogoutOtherSessions(props: { getClassName: ReturnType<typeof useGetClassName>["getClassName"]; i18n: I18n }) {
|
||||||
|
const { getClassName, i18n } = props;
|
||||||
|
|
||||||
|
const { msg } = i18n;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div id="kc-form-options" className={getClassName("kcFormOptionsClass")}>
|
||||||
|
<div className={getClassName("kcFormOptionsWrapperClass")}>
|
||||||
|
<div className="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="logout-sessions" name="logout-sessions" value="on" defaultChecked={true} />
|
||||||
|
{msg("logoutOtherSessions")}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function PasswordWrapper(props: {
|
||||||
|
getClassName: ReturnType<typeof useGetClassName>["getClassName"];
|
||||||
|
i18n: I18n;
|
||||||
|
passwordInputId: string;
|
||||||
|
children: JSX.Element;
|
||||||
|
}) {
|
||||||
|
const { getClassName, i18n, passwordInputId, children } = props;
|
||||||
|
|
||||||
|
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 (
|
||||||
|
<div className={getClassName("kcInputGroup")}>
|
||||||
|
{children}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={getClassName("kcFormPasswordVisibilityButtonClass")}
|
||||||
|
aria-label={msgStr(isPasswordRevealed ? "hidePassword" : "showPassword")}
|
||||||
|
aria-controls={passwordInputId}
|
||||||
|
onClick={toggleIsPasswordRevealed}
|
||||||
|
>
|
||||||
|
<i
|
||||||
|
className={getClassName(isPasswordRevealed ? "kcFormPasswordVisibilityIconHide" : "kcFormPasswordVisibilityIconShow")}
|
||||||
|
aria-hidden
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user