Skip to content

Commit e865a43

Browse files
authored
OZ-979: Merge username and password into a single login page (#205)
1 parent 690c39b commit e865a43

File tree

2 files changed

+6
-77
lines changed

2 files changed

+6
-77
lines changed

distro/configs/keycloak/themes/carbon/login/login.ftl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,9 @@
6969
</div>
7070
</div>
7171
</div>
72-
<button type="submit" class="continue-button btn-primary">
73-
${msg("doContinue")}
74-
<svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor"
75-
aria-label="Next" aria-hidden="true" width="24" height="24" viewBox="0 0 24 24" role="img" class="btn-icon">
76-
<path d="M14 4L12.9 5.1 18.9 11.2 2 11.2 2 12.8 18.9 12.8 12.9 18.9 14 20 22 12z"></path>
77-
</svg>
78-
</button>
7972
</div>
8073

81-
<div class="input-group hidden" id="password-tab">
74+
<div class="input-group" id="password-tab">
8275
<div class="form-item">
8376
<label for="password" class="label">${msg("password")}</label>
8477
<div class="text-input-field-outer-wrapper">

distro/configs/keycloak/themes/carbon/login/resources/js/script.js

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,11 @@ document.addEventListener("DOMContentLoaded", () => {
1010
)
1111
);
1212

13-
const usernameTab = document.getElementById("username-tab");
14-
const passwordTab = document.getElementById("password-tab");
1513
const usernameInput = document.getElementById("username");
1614
const passwordInput = document.getElementById("password");
1715
const loginForm = document.getElementById("kc-form-login");
1816
const passwordToggleButton = document.getElementById("password-toggle");
1917

20-
const Tabs = {
21-
username: "username",
22-
password: "password",
23-
};
24-
25-
let username = "";
26-
let password = "";
27-
let isUsernameInvalid = false;
28-
let isPasswordInvalid = false;
29-
let currentTab = Tabs.username;
3018
let showPassword = false;
3119

3220
passwordToggleButton.addEventListener("click", () => {
@@ -42,69 +30,17 @@ document.addEventListener("DOMContentLoaded", () => {
4230
}
4331
});
4432

45-
/** Updates the login UI to reflect the internal state. */
46-
function syncUiWithState() {
47-
usernameInput.value = username;
48-
passwordInput.value = password;
49-
usernameInput.classList.toggle("invalid", isUsernameInvalid);
50-
passwordInput.classList.toggle("invalid", isPasswordInvalid);
51-
usernameTab.classList.toggle("hidden", currentTab !== Tabs.username);
52-
passwordTab.classList.toggle("hidden", currentTab !== Tabs.password);
53-
}
54-
55-
/**
56-
* Called when the form is submitted.
57-
* This returns whether the form submission should be prevented
58-
* or not (i.e. whether the form data should be sent to the server).
59-
*
60-
* The latter should only happen when both the username and password are
61-
* valid for submission (i.e. non-empty).
62-
*/
63-
function handleFormSubmit() {
64-
if (currentTab === Tabs.username) {
65-
username = usernameInput.value;
66-
isUsernameInvalid = !username;
67-
68-
if (!isUsernameInvalid) {
69-
currentTab = Tabs.password;
70-
}
71-
72-
// In the username step, we always want to prevent the form
73-
// from being submitted because the user still has to enter
74-
// the password.
75-
syncUiWithState();
76-
passwordInput.focus();
77-
return true;
78-
} else if (currentTab === Tabs.password) {
79-
password = passwordInput.value;
80-
isPasswordInvalid = !password;
81-
82-
// In the password step we only want to prevent the form
83-
// from being submitted while the password is invalid.
84-
syncUiWithState();
85-
return isPasswordInvalid;
86-
} else {
87-
console.error(
88-
`Arrived at an invalid tab: "${currentTab}". ` +
89-
`This is most likely an error in the code and should be fixed. ` +
90-
`Resetting to the initial tab.`
91-
);
92-
93-
currentTab = Tabs.username;
94-
syncUiWithState();
95-
return true;
96-
}
97-
}
98-
9933
loginForm.onsubmit = (e) => {
100-
const shouldPreventFormSubmit = handleFormSubmit();
101-
if (shouldPreventFormSubmit) {
34+
const username = usernameInput.value.trim();
35+
const password = passwordInput.value.trim();
36+
37+
if (!username || !password) {
10238
e.preventDefault();
10339
return false;
10440
} else {
10541
// This has been moved out of the KC ftl template.
10642
// It is, by default, present in the following form:
107-
// <form onsubmit="login.disabled = true; return true;" action="${url.loginAction}" method="post" ...>
43+
// <form onsubmit="login.disabled = true; return true;" action="${url.loginAction}" method="post" ...>
10844
// It is moved here, because we require special submission
10945
// handling due to the form having 2 steps.
11046
login.disabled = true;

0 commit comments

Comments
 (0)