Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
"license": "MIT",
"keycloakify": {
"themeName": "dsfr",
"extraThemeNames": [
"dsfr-no-login-form"
],
"extraThemeProperties": [
"homeUrl=${env.DSFR_THEME_HOME_URL:}",
"serviceTitle=${env.DSFR_THEME_SERVICE_TITLE:}",
"brandTop=${env.DSFR_THEME_BRAND_TOP:}",
"tosUrl=${env.DSFR_THEME_TOS_URL:}",
"contactEmail=${env.DSFR_THEME_CONTACT_EMAIL:}"
"contactEmail=${env.DSFR_THEME_CONTACT_EMAIL:}",
"loginHtml=${env.DSFR_THEME_LOGIN_HTML:}"
]
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/Properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export type Properties = {
brandTop: string;
tosUrl: string;
contactEmail: string;
loginHtml: string;
};
217 changes: 126 additions & 91 deletions src/login/pages/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, type FormEventHandler } from "react";
import { useState, type FormEventHandler, useEffect } from "react";
import { useConstCallback } from "keycloakify/tools/useConstCallback";
import type { PageProps } from "keycloakify/login/pages/PageProps";
import { tss } from "tss-react/dsfr";
Expand All @@ -23,8 +23,16 @@ export default function Login(
"classes": classes_props
});

const { social, realm, url, usernameHidden, login, auth, registrationDisabled } =
kcContext;
const {
social,
realm,
url,
usernameHidden,
login,
auth,
registrationDisabled,
themeName
} = kcContext;

const { msg, msgStr } = i18n;
const { classes, cx } = useStyles();
Expand All @@ -47,6 +55,10 @@ export default function Login(
formElement.submit();
});

useEffect(() => {
if (realm.displayName) document.title = realm.displayName;
}, []);

return (
<Template
{...{ kcContext, i18n, doUseDefaultCss, "classes": classes_props }}
Expand Down Expand Up @@ -133,6 +145,9 @@ export default function Login(
/>
) : (
<Button
className={
classes.btnSocialProvider
}
linkProps={{
"href": p.loginUrl
}}
Expand All @@ -145,104 +160,121 @@ export default function Login(
</div>
</div>
)}
<h5>{msgStr("selfCredentials")}</h5>
<div className={classes.inputs}>
{(() => {
const label = !realm.loginWithEmailAllowed
? "username"
: realm.registrationEmailAsUsername
? "email"
: "usernameOrEmail";

const autoCompleteHelper: typeof label =
label === "usernameOrEmail" ? "username" : label;
{themeName !== "dsfr-dnum-no-login-form" && (
<>
<h5>{msgStr("selfCredentials")}</h5>
<div className={classes.inputs}>
{(() => {
const label = !realm.loginWithEmailAllowed
? "username"
: realm.registrationEmailAsUsername
? "email"
: "usernameOrEmail";

const autoCompleteHelper: typeof label =
label === "usernameOrEmail"
? "username"
: label;

return (
<Input
return (
<Input
nativeInputProps={{
"tabIndex": 1,
"id": autoCompleteHelper,
"name": autoCompleteHelper,
"type": "email",
"defaultValue":
login.username ?? "",
...(usernameHidden
? { "disabled": true }
: {
"autoFocus": true,
"autoComplete": "off"
})
}}
label={msgStr("email")}
hintText={msgStr("email hint")}
/>
);
})()}
<PasswordInput
label={msgStr("password")}
nativeInputProps={{
"tabIndex": 1,
"id": autoCompleteHelper,
"name": autoCompleteHelper,
"type": "email",
"defaultValue": login.username ?? "",
...(usernameHidden
? { "disabled": true }
: {
"autoFocus": true,
"autoComplete": "off"
})
"tabIndex": 2,
"id": "password",
"name": "password",
"autoComplete": "off"
}}
label={msgStr("email")}
hintText={msgStr("email hint")}
/>
);
})()}
<PasswordInput
label={msgStr("password")}
nativeInputProps={{
"tabIndex": 2,
"id": "password",
"name": "password",
"autoComplete": "off"
}}
/>
<div
className={cx(
getClassName("kcFormGroupClass"),
getClassName("kcFormSettingClass")
)}
>
<div id="kc-form-options">
{realm.rememberMe && !usernameHidden && (
<Checkbox
className={classes.rememberMe}
options={[
{
"label": msg("rememberMe"),
"nativeInputProps": {
"tabIndex": 3,
"name": "rememberMe",
...(login.rememberMe
? {
"checked": true
}
: {})
}
}
]}
/>
)}
<div
className={cx(
getClassName("kcFormGroupClass"),
getClassName("kcFormSettingClass")
)}
>
<div id="kc-form-options">
{realm.rememberMe && !usernameHidden && (
<Checkbox
className={classes.rememberMe}
options={[
{
"label":
msg("rememberMe"),
"nativeInputProps": {
"tabIndex": 3,
"name": "rememberMe",
...(login.rememberMe
? {
"checked":
true
}
: {})
}
}
]}
/>
)}
</div>
</div>
</div>
</div>
</div>
<div
id="kc-form-buttons"
className={getClassName("kcFormGroupClass")}
>
<input
type="hidden"
id="id-hidden-input"
name="credentialId"
{...(auth?.selectedCredential !== undefined
? {
"value": auth.selectedCredential
}
: {})}
/>
<input
tabIndex={4}
className={fr.cx("fr-btn")}
name="login"
id="kc-login"
type="submit"
value={msgStr("connect")}
disabled={isLoginButtonDisabled}
/>
</div>
<div
id="kc-form-buttons"
className={getClassName("kcFormGroupClass")}
>
<input
type="hidden"
id="id-hidden-input"
name="credentialId"
{...(auth?.selectedCredential !== undefined
? {
"value": auth.selectedCredential
}
: {})}
/>
<input
tabIndex={4}
className={fr.cx("fr-btn")}
name="login"
id="kc-login"
type="submit"
value={msgStr("connect")}
disabled={isLoginButtonDisabled}
/>
</div>
</>
)}
</form>
)}
</div>
</div>
{kcContext.properties.loginHtml && (
<div
dangerouslySetInnerHTML={{
"__html": kcContext.properties.loginHtml
}}
/>
)}
</Template>
);
}
Expand All @@ -263,6 +295,9 @@ const useStyles = tss.withName({ Login }).create({
"borderRight": "none"
}
},
"btnSocialProvider": {
"marginBottom": fr.spacing("6v")
},
"forgotPassword": {
"marginRight": fr.spacing("6v")
},
Expand Down