fix the version number in UI. Enable the remember username/password functionality in browser.

This commit is contained in:
cjkas 2026-04-22 14:16:11 +02:00
parent 15e7dd1ee2
commit 4f7fa73313
3 changed files with 33 additions and 16 deletions

View file

@ -1026,21 +1026,23 @@
<label for="fldPinEntry" style="margin-top:7px;">Enter Pin</label> <label for="fldPinEntry" style="margin-top:7px;">Enter Pin</label>
</div> </div>
</div> </div>
<div id="divLoginPassword" style="display:none;" onkeyup="if (event.code === 'Enter') security.login();"> <form id="frmUnauthLogin" action="/login" method="post" onsubmit="security.login(event); return false;">
<div id="divLoginPassword" style="display:none;">
<div class="field-group"> <div class="field-group">
<input id="fldLoginUsername" name="username" type="text" data-bind="login.username" length=32 placeholder="Username" /> <input id="fldLoginUsername" name="username" type="text" autocomplete="username" data-bind="login.username" length=32 placeholder="Username" />
<label for="fldLoginUsername">Username</label> <label for="fldLoginUsername">Username</label>
</div> </div>
<div class="field-group"> <div class="field-group">
<input id="fldLoginPassword" name="password" type="password" data-bind="login.password" length=32 placeholder="Password" /> <input id="fldLoginPassword" name="password" type="password" autocomplete="current-password" data-bind="login.password" length=32 placeholder="Password" />
<label for="fldLoginPassword">Password</label> <label for="fldLoginPassword">Password</label>
</div> </div>
</div> </div>
<div style="text-align:center;"><span id="spanLoginMessage" style="color:red"></span></div> <div style="text-align:center;"><span id="spanLoginMessage" style="color:red"></span></div>
<div id="loginButtons" class="button-container" style="display:none;text-align:center;"> <div id="loginButtons" class="button-container" style="display:none;text-align:center;">
<button id="btnLogin" type="button" onclick="security.login();" style="display:inline-block;width:42%;">Login</button> <button id="btnLogin" type="submit" style="display:inline-block;width:42%;">Login</button>
<button id="btnCancelLogin" type="button" onclick="security.cancelLogin();" style="display:none;width:42%;">Cancel</button> <button id="btnCancelLogin" type="button" onclick="security.cancelLogin();" style="display:none;width:42%;">Cancel</button>
</div> </div>
</form>
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">

View file

@ -1228,7 +1228,8 @@ class Security {
document.getElementById('divUnauthenticated').style.display = 'none'; document.getElementById('divUnauthenticated').style.display = 'none';
document.getElementById('divContainer').dispatchEvent(evt); document.getElementById('divContainer').dispatchEvent(evt);
} }
login() { login(evt) {
if (evt && evt.preventDefault) evt.preventDefault();
console.log('Logging in...'); console.log('Logging in...');
let pnl = document.getElementById('divUnauthenticated'); let pnl = document.getElementById('divUnauthenticated');
let msg = pnl.querySelector('#spanLoginMessage'); let msg = pnl.querySelector('#spanLoginMessage');
@ -1241,7 +1242,7 @@ class Security {
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
pin += sec.pin[`d${i}`]; pin += sec.pin[`d${i}`];
} }
if (pin.length !== 4) return; if (pin.length !== 4) return false;
break; break;
case 2: case 2:
break; break;
@ -1252,6 +1253,16 @@ class Security {
else { else {
console.log(log); console.log(log);
if (log.success) { if (log.success) {
if (sec.type === 2 && window.PasswordCredential && navigator.credentials) {
try {
const cred = new PasswordCredential({
id: sec.username,
password: sec.password,
name: sec.username
});
navigator.credentials.store(cred);
} catch (e) { /* ignore; browsers without support fall back to the form-submit heuristic */ }
}
if (typeof socket === 'undefined' || !socket) (async () => { await initSockets(); })(); if (typeof socket === 'undefined' || !socket) (async () => { await initSockets(); })();
//ui.setMode(mode); //ui.setMode(mode);
@ -1260,13 +1271,14 @@ class Security {
document.getElementById('divContainer').setAttribute('data-auth', true); document.getElementById('divContainer').setAttribute('data-auth', true);
this.apiKey = log.apiKey; this.apiKey = log.apiKey;
this.authenticated = true; this.authenticated = true;
let evt = new CustomEvent('afterlogin', { detail: { authenticated: true } }); let evt2 = new CustomEvent('afterlogin', { detail: { authenticated: true } });
document.getElementById('divContainer').dispatchEvent(evt); document.getElementById('divContainer').dispatchEvent(evt2);
} }
else else
msg.innerHTML = log.msg; msg.innerHTML = log.msg;
} }
}); });
return false;
} }
} }
var security = new Security(); var security = new Security();
@ -1274,7 +1286,7 @@ var security = new Security();
// let appVersion = 'v3.0.12'; // Default placeholder // let appVersion = 'v3.0.12'; // Default placeholder
async function getAppVersion() { async function getAppVersion() {
try { try {
const response = await fetch('/appversion'); const response = await fetch('/appversion?v='+Date.now());
if (!response.ok) throw new Error('File not found'); if (!response.ok) throw new Error('File not found');
const data = await response.text(); const data = await response.text();
@ -1290,8 +1302,8 @@ async function getAppVersion() {
} }
class General { class General {
initialized = false; initialized = false;
appVersion = getAppVersion(); appVersion = '';
reloadApp = false; reloadApp = false;
init() { init() {
if (this.initialized) return; if (this.initialized) return;
@ -1468,7 +1480,10 @@ class General {
} }
}); });
} }
setAppVersion() { document.getElementById('spanAppVersion').innerText = this.appVersion; } async setAppVersion() {
this.appVersion = await getAppVersion();
document.getElementById('spanAppVersion').innerText = this.appVersion;
}
setTimeZones() { setTimeZones() {
let dd = document.getElementById('selTimeZone'); let dd = document.getElementById('selTimeZone');
dd.length = 0; dd.length = 0;

View file

@ -14,7 +14,7 @@
<h1 style="text-align: center;"><img src="icon.png" style="width:127px;margin-left:1px;margin-top:-10px;" /></h1> <h1 style="text-align: center;"><img src="icon.png" style="width:127px;margin-left:1px;margin-top:-10px;" /></h1>
<div id="divLoginPnl" class="login-content" style="position:relative;"> <div id="divLoginPnl" class="login-content" style="position:relative;">
<div style="max-width:270px;margin:0px auto;"> <div style="max-width:270px;margin:0px auto;">
<form id="frmLogin" action="/login" method="post" class="login-form"> <form id="frmLogin" action="/login" method="post" class="login-form" onsubmit="general.login(event); return false;">
<input id="fldPin" type="hidden" name="pin"> <input id="fldPin" type="hidden" name="pin">
<div id="divPinSecurity" style="display:none;"> <div id="divPinSecurity" style="display:none;">
<div class="field-group" style="text-align:center;"> <div class="field-group" style="text-align:center;">
@ -29,17 +29,17 @@
</div> </div>
<div id="divPasswordSecurity" style="display:none;"> <div id="divPasswordSecurity" style="display:none;">
<div class="field-group"> <div class="field-group">
<input id="fldUsername" name="username" type="text" data-bind="security.username" length=32 placeholder="Username"> <input id="fldUsername" name="username" type="text" autocomplete="username" data-bind="security.username" length=32 placeholder="Username">
<label for="fldUsername">Username</label> <label for="fldUsername">Username</label>
</div> </div>
<div class="field-group"> <div class="field-group">
<input id="fldPassword" name="password" type="password" data-bind="security.password" length=32 placeholder="Password"> <input id="fldPassword" name="password" type="password" autocomplete="current-password" data-bind="security.password" length=32 placeholder="Password">
<label for="fldPassword">Password</label> <label for="fldPassword">Password</label>
</div> </div>
</div> </div>
<div style="text-align:center;"><span id="spanLoginMessage" style="color:red"></span></div> <div style="text-align:center;"><span id="spanLoginMessage" style="color:red"></span></div>
<div class="button-container"> <div class="button-container">
<button id="btnLogin" type="button" value="Submit" onclick="general.login();"> <button id="btnLogin" type="submit" value="Submit">
Login Login
</button> </button>
</div> </div>