Expand password dialog to work for usernames too

Some VNC authentication schemes use usernames, our UI should support
these.
This commit is contained in:
Chris Koying Browet 2019-12-05 15:34:18 +01:00 committed by Samuel Mannehed
parent b39caa7469
commit 5b453ed4a8
3 changed files with 46 additions and 19 deletions

View File

@ -790,19 +790,23 @@ select:active {
* ----------------------------------------
*/
#noVNC_password_dlg {
#noVNC_credentials_dlg {
position: relative;
transform: translateY(-50px);
}
#noVNC_password_dlg.noVNC_open {
#noVNC_credentials_dlg.noVNC_open {
transform: translateY(0);
}
#noVNC_password_dlg ul {
#noVNC_credentials_dlg ul {
list-style: none;
margin: 0px;
padding: 0px;
}
.noVNC_hidden {
display: none;
}
/* ----------------------------------------
* Main Area

View File

@ -316,8 +316,8 @@ const UI = {
document.getElementById("noVNC_cancel_reconnect_button")
.addEventListener('click', UI.cancelReconnect);
document.getElementById("noVNC_password_button")
.addEventListener('click', UI.setPassword);
document.getElementById("noVNC_credentials_button")
.addEventListener('click', UI.setCredentials);
},
addClipboardHandlers() {
@ -440,7 +440,7 @@ const UI = {
}
// State change closes the password dialog
document.getElementById('noVNC_password_dlg')
document.getElementById('noVNC_credentials_dlg')
.classList.remove('noVNC_open');
},
@ -1147,27 +1147,46 @@ const UI = {
credentials(e) {
// FIXME: handle more types
document.getElementById('noVNC_password_dlg')
document.getElementById("noVNC_username_block").classList.remove("noVNC_hidden");
document.getElementById("noVNC_password_block").classList.remove("noVNC_hidden");
let inputFocus = "none";
if (!e.detail.types.includes("username")) {
document.getElementById("noVNC_username_block").classList.add("noVNC_hidden");
} else {
inputFocus = inputFocus === "none" ? "noVNC_username_input" : inputFocus;
}
if (!e.detail.types.includes("password")) {
document.getElementById("noVNC_password_block").classList.add("noVNC_hidden");
} else {
inputFocus = inputFocus === "none" ? "noVNC_password_input" : inputFocus;
}
document.getElementById('noVNC_credentials_dlg')
.classList.add('noVNC_open');
setTimeout(() => document
.getElementById('noVNC_password_input').focus(), 100);
.getElementById(inputFocus).focus(), 100);
Log.Warn("Server asked for a password");
UI.showStatus(_("Password is required"), "warning");
Log.Warn("Server asked for credentials");
UI.showStatus(_("Credentials are required"), "warning");
},
setPassword(e) {
setCredentials(e) {
// Prevent actually submitting the form
e.preventDefault();
const inputElem = document.getElementById('noVNC_password_input');
const password = inputElem.value;
let inputElemUsername = document.getElementById('noVNC_username_input');
const username = inputElemUsername.value;
let inputElemPassword = document.getElementById('noVNC_password_input');
const password = inputElemPassword.value;
// Clear the input after reading the password
inputElem.value = "";
UI.rfb.sendCredentials({ password: password });
inputElemPassword.value = "";
UI.rfb.sendCredentials({ username: username, password: password });
UI.reconnect_password = password;
document.getElementById('noVNC_password_dlg')
document.getElementById('noVNC_credentials_dlg')
.classList.remove('noVNC_open');
},

View File

@ -285,14 +285,18 @@
<!-- Password Dialog -->
<div class="noVNC_center noVNC_connect_layer">
<div id="noVNC_password_dlg" class="noVNC_panel"><form>
<div id="noVNC_credentials_dlg" class="noVNC_panel"><form>
<ul>
<li>
<li id="noVNC_username_block">
<label>Username:</label>
<input id="noVNC_username_input">
</li>
<li id="noVNC_password_block">
<label>Password:</label>
<input id="noVNC_password_input" type="password">
</li>
<li>
<input id="noVNC_password_button" type="submit" value="Send Password" class="noVNC_submit">
<input id="noVNC_credentials_button" type="submit" value="Send Credentials" class="noVNC_submit">
</li>
</ul>
</form></div>