mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Avoid saving passwords in session storage.
This commit is contained in:
parent
3e52ac1253
commit
4d5e6a319a
2 changed files with 10 additions and 65 deletions
2
CHANGES
2
CHANGES
|
@ -11,6 +11,8 @@ Galène 0.4.1 (unreleased):
|
||||||
* Allow scrolling of the login dialog, useful on small devices.
|
* Allow scrolling of the login dialog, useful on small devices.
|
||||||
* Fixed a typo that prevented the group name from being displayed.
|
* Fixed a typo that prevented the group name from being displayed.
|
||||||
* Made failed videos more visible.
|
* Made failed videos more visible.
|
||||||
|
* No longer attempt to save passwords in browser JavaScript, it's
|
||||||
|
insecure and not very useful.
|
||||||
|
|
||||||
5 September 2021: Galène 0.4
|
5 September 2021: Galène 0.4
|
||||||
|
|
||||||
|
|
|
@ -29,52 +29,8 @@ let serverConnection;
|
||||||
/** @type {Object} */
|
/** @type {Object} */
|
||||||
let groupStatus = {};
|
let groupStatus = {};
|
||||||
|
|
||||||
/**
|
/** @type {string} */
|
||||||
* @typedef {Object} userpass
|
let username = null;
|
||||||
* @property {string} username
|
|
||||||
* @property {string} password
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Some browsers disable session storage when cookies are disabled,
|
|
||||||
we fall back to a global variable. */
|
|
||||||
/**
|
|
||||||
* @type {userpass}
|
|
||||||
*/
|
|
||||||
let fallbackUserPass = null;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} username
|
|
||||||
* @param {string} password
|
|
||||||
*/
|
|
||||||
function storeUserPass(username, password) {
|
|
||||||
let userpass = {username: username, password: password};
|
|
||||||
try {
|
|
||||||
window.sessionStorage.setItem('userpass', JSON.stringify(userpass));
|
|
||||||
fallbackUserPass = null;
|
|
||||||
} catch(e) {
|
|
||||||
console.warn("Couldn't store password:", e);
|
|
||||||
fallbackUserPass = userpass;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns null if the user hasn't logged in yet.
|
|
||||||
*
|
|
||||||
* @returns {userpass}
|
|
||||||
*/
|
|
||||||
function getUserPass() {
|
|
||||||
/** @type{userpass} */
|
|
||||||
let userpass;
|
|
||||||
try {
|
|
||||||
let json = window.sessionStorage.getItem('userpass');
|
|
||||||
userpass = JSON.parse(json);
|
|
||||||
} catch(e) {
|
|
||||||
console.warn("Couldn't retrieve password:", e);
|
|
||||||
userpass = fallbackUserPass;
|
|
||||||
}
|
|
||||||
return userpass || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} settings
|
* @typedef {Object} settings
|
||||||
|
@ -291,14 +247,6 @@ function showVideo() {
|
||||||
scheduleReconsiderDownRate();
|
scheduleReconsiderDownRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillLogin() {
|
|
||||||
let userpass = getUserPass();
|
|
||||||
getInputElement('username').value =
|
|
||||||
userpass ? userpass.username : '';
|
|
||||||
getInputElement('password').value =
|
|
||||||
userpass ? userpass.password : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param{boolean} connected
|
* @param{boolean} connected
|
||||||
*/
|
*/
|
||||||
|
@ -314,7 +262,6 @@ function setConnected(connected) {
|
||||||
scheduleReconsiderDownRate();
|
scheduleReconsiderDownRate();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fillLogin();
|
|
||||||
userbox.classList.add('invisible');
|
userbox.classList.add('invisible');
|
||||||
connectionbox.classList.remove('invisible');
|
connectionbox.classList.remove('invisible');
|
||||||
displayError('Disconnected', 'error');
|
displayError('Disconnected', 'error');
|
||||||
|
@ -325,10 +272,12 @@ function setConnected(connected) {
|
||||||
|
|
||||||
/** @this {ServerConnection} */
|
/** @this {ServerConnection} */
|
||||||
function gotConnected() {
|
function gotConnected() {
|
||||||
|
username = getInputElement('username').value.trim();
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
let up = getUserPass();
|
|
||||||
try {
|
try {
|
||||||
this.join(group, up.username, up.password);
|
let pw = getInputElement('password').value;
|
||||||
|
getInputElement('password').value = '';
|
||||||
|
this.join(group, username, pw);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
displayError(e);
|
displayError(e);
|
||||||
|
@ -2086,10 +2035,8 @@ function gotUser(id, kind) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayUsername() {
|
function displayUsername() {
|
||||||
let userpass = getUserPass();
|
document.getElementById('userspan').textContent = username;
|
||||||
let text = '';
|
let text = '';
|
||||||
if(userpass && userpass.username)
|
|
||||||
document.getElementById('userspan').textContent = userpass.username;
|
|
||||||
if(serverConnection.permissions.op && serverConnection.permissions.present)
|
if(serverConnection.permissions.op && serverConnection.permissions.present)
|
||||||
text = '(op, presenter)';
|
text = '(op, presenter)';
|
||||||
else if(serverConnection.permissions.op)
|
else if(serverConnection.permissions.op)
|
||||||
|
@ -2997,10 +2944,7 @@ document.getElementById('userform').onsubmit = async function(e) {
|
||||||
return;
|
return;
|
||||||
connecting = true;
|
connecting = true;
|
||||||
try {
|
try {
|
||||||
let username = getInputElement('username').value.trim();
|
await serverConnect();
|
||||||
let password = getInputElement('password').value;
|
|
||||||
storeUserPass(username, password);
|
|
||||||
serverConnect();
|
|
||||||
} finally {
|
} finally {
|
||||||
connecting = false;
|
connecting = false;
|
||||||
}
|
}
|
||||||
|
@ -3118,7 +3062,6 @@ async function start() {
|
||||||
addFilters();
|
addFilters();
|
||||||
setMediaChoices(false).then(e => reflectSettings());
|
setMediaChoices(false).then(e => reflectSettings());
|
||||||
|
|
||||||
fillLogin();
|
|
||||||
document.getElementById("login-container").classList.remove('invisible');
|
document.getElementById("login-container").classList.remove('invisible');
|
||||||
setViewportHeight();
|
setViewportHeight();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue