refs #4974 Added logout button and auto-login

This commit is contained in:
Guillermo Bonet 2023-02-08 15:32:25 +01:00
parent 1a6f22e539
commit 12caa4014a
4 changed files with 73 additions and 56 deletions

BIN
src/logout.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

View File

@ -41,7 +41,9 @@ var Locale = {
"MDB file not found":
"No se encontró el fichero MDB",
"Cache files have been deleted":
"Se han borrado todos los ficheros almacenados en la caché"
"Se han borrado todos los ficheros almacenados en la caché",
"Session has been closed":
"Se han cerrado la sesión"
}
};
@ -52,7 +54,7 @@ var App = {
init: function() {
// Specify the size of window
var width = 420;
var height = 570;
var height = 590;
window.resizeTo(width, height);
window.moveTo((screen.width - width) / 2, (screen.height - height) / 2);
},
@ -113,8 +115,16 @@ var App = {
this.regDelete(Conf.regPath +'\\configured');
this.regDelete(Conf.regPath + '\\remember');
}
var notSignOut = this.regRead(Conf.regPath, 'notSignOut');
this.$('notSignOut').checked = notSignOut;
if (!notSignOut)
this.resetForm(true);
var autoLogin = this.regRead(Conf.regPath, 'autoLogin');
this.$('autoLogin').checked = autoLogin;
this.refreshLogout();
// Branch options
this.request('GET', 'mdbBranches', null, function(err, res) {
@ -154,13 +164,13 @@ var App = {
}
this.$('datasource').value = this.dsName;
if (notSignOut && password) {
this.$('notSignOut').checked = true;
this.onChangeDatasource(true);
if (autoLogin) {
this.onChangeDatasource();
this.onEnterClick();
} else {
this.resetForm(true);
this.onChangeDatasource(true);
if (!notSignOut)
this.resetForm(true);
this.onChangeDatasource();
}
},
isDs: function(dsName) {
@ -172,11 +182,13 @@ var App = {
: dsName;
},
resetForm: function(clearPassword) {
if (clearPassword)
if (clearPassword) {
this.$('password').value = '';
this.regWrite(this.getOdbcPath(), 'PWD', '');
}
this.$('user').focus();
this.$('user').select();
this.$('password').focus();
this.$('password').select();
},
createODBC: function(path, dsName, driverName, description) {
var driverPath = this.getEnv('ProgramFiles') + Conf.driverPath;
@ -195,21 +207,6 @@ var App = {
this.regWrite(path + 'ODBC Data Sources', dsName, driverName);
this.regWrites(path + dsName, params);
},
updateODBC: function() {
var odbcPath = this.getOdbcPath();
var myUID = this.regRead(odbcPath, 'remoteUser');
var myPWD = this.regRead(odbcPath, 'remotePass');
var params = [];
if (myUID && myPWD) {
params['UID'] = myUID;
params['PWD'] = myPWD;
} else {
params['UID'] = this.regRead(odbcPath, 'UID');
params['PWD'] = this.regRead(odbcPath, 'PWD');
}
this.regWrites(odbcPath, params);
},
disableUi: function(disabled, loadMessage) {
if (disabled)
this.hideMessage();
@ -221,6 +218,7 @@ var App = {
this.$('user').disabled = disabled;
this.$('password').disabled = disabled;
this.$('notSignOut').disabled = disabled;
this.$('autoLogin').disabled = disabled;
this.$('enter').disabled = disabled;
var display = disabled ? 'block' : 'none';
@ -248,6 +246,14 @@ var App = {
this.$('datasourceLogo').className = '';
},
refreshLogout: function() {
var style = this.$('logout').style;
var password = this.regRead(this.getOdbcPath(), 'PWD');
if (password)
style.display = 'inline';
else
style.display = 'none';
},
onChangeBranch: function() {
if (this.$('branch').value == 'master'||'test'||'dev') {
this.$('branchButton').className = this.$('branch').value;
@ -263,7 +269,7 @@ var App = {
*
* @param {Boolean} hasUpdate
*/
onChangeDatasource: function(hasUpdate) {
onChangeDatasource: function() {
this.dsName = this.$('datasource').value;
var myDatasource = this.getDatasource(this.dsName);
@ -277,25 +283,11 @@ var App = {
this.$('datasourceButton').className = null;
this.$('datasource').className = null;
};
if (!hasUpdate) {
this.updateODBC();
};
var odbcPath = this.getOdbcPath();
var myUID = this.regRead(odbcPath, 'remoteUser');
var myPWD = this.regRead(odbcPath, 'remotePass');
var notSignOut = this.regRead(Conf.regPath, 'notSignOut');
if (myUID && myPWD && !notSignOut) {
this.$('user').value = myUID;
this.$('password').value = myPWD;
} else {
var user = this.regRead(odbcPath, 'UID')
if (user)
this.$('user').value = user
if (!notSignOut)
this.resetForm(true)
else
this.$('password').value = this.regRead(odbcPath, 'PWD')
}
this.$('user').value = this.regRead(odbcPath, 'UID')
this.$('password').value = this.regRead(odbcPath, 'PWD')
this.refreshLogout();
this.$('user').focus();
},
@ -383,6 +375,11 @@ var App = {
this.catchError(err);
}
},
logout: function() {
this.resetForm(true);
this.refreshLogout();
this.showMessage(_('Session has been closed'), 'notice');
},
/**
* Gets information about the version to download.
* cmdle
@ -532,9 +529,17 @@ var App = {
}
},
openMdb: function() {
var notSignOut = !!this.$('notSignOut').checked;
var autoLogin = this.$('autoLogin').checked;
this.regWrite(Conf.regPath, 'autoLogin', autoLogin);
if (autoLogin)
var notSignOut = true;
else
var notSignOut = this.$('notSignOut').checked;
this.regWrite(Conf.regPath, 'notSignOut', notSignOut);
this.$('notSignOut').checked = true;
var programFiles = this.getEnv('ProgramFiles');
var accessBin = programFiles +'\\Microsoft Office\\OFFICE11\\MSACCESS.EXE';
@ -548,11 +553,8 @@ var App = {
catchError: function(err) {
var clearPassword = err.name == 'BadLogin';
if (this.$('notSignOut').checked) {
this.regWrite(this.getOdbcPath(), 'PWD', '');
this.regWrite(Conf.regPath, 'notSignOut', 0)
this.$('notSignOut').checked = false
}
this.regWrite(Conf.regPath, 'autoLogin', 0)
this.$('autoLogin').checked = false
this.disableUi(false);
this.showMessage(err.message, 'error');

View File

@ -61,11 +61,22 @@ input[type='text']:focus,
input[type='password']:focus {
border-bottom: 1px solid black;
}
#notSignOutSection {
#optionsSection {
margin-top: 1em;
font-size: .8em;
margin-bottom: 2.5em;
}
#logout {
float: right;
margin-top: -4.3em;
margin-left: .4em;
padding: .4em;
}
#logout:hover {
border-radius: 25px;
background-color: #f0f0f0;
cursor: pointer;
}
#submit {
margin-top: 1em;
}

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8" http-equiv="X-UA-Compatible" content="IE=9"/>
<title></title>
<title>v5</title>
<link rel="stylesheet" href="style.css"/>
<script type="text/javascript" src="main.js"></script>
<hta:application
@ -41,10 +41,14 @@
<input id="password" type="password"/>
</div>
</div>
<div id="notSignOutSection">
<input id="notSignOut" type="checkbox"/>
<div id="optionsSection">
<input id="notSignOut" type="checkbox">
<label for="notSignOut">No cerrar sesión</label>
<br/>
<input id="autoLogin" type="checkbox"/>
<label for="autoLogin">Auto-login</label>
</div>
<img id="logout" src="logout.png" onclick="App.logout()"/>
</div>
<div id="submit">
<button id="enter" onclick="App.onEnterClick()">Iniciar sesión</button>
@ -72,7 +76,7 @@
onclick="App.openOptions()"
alt="Change datasource"/>
<div id="datasourceSelector">
<select id="datasource" onchange="App.onChangeDatasource(false)">
<select id="datasource" onchange="App.onChangeDatasource()">
</select>
</div>
</div>