mirror of
https://github.com/jech/galene.git
synced 2024-11-23 00:55:58 +01:00
Make login work when sessionStorage is not available.
Thanks to Ralf Treinen for pointing out the issue.
This commit is contained in:
parent
4bdd7c7665
commit
517d7edbc8
1 changed files with 21 additions and 8 deletions
|
@ -11,18 +11,31 @@ let group;
|
||||||
/** @type {ServerConnection} */
|
/** @type {ServerConnection} */
|
||||||
let serverConnection;
|
let serverConnection;
|
||||||
|
|
||||||
|
/* Some browsers disable session storage when cookies are disabled,
|
||||||
|
we fall back to a global variable. */
|
||||||
|
let fallbackUserPass = null;
|
||||||
|
|
||||||
function setUserPass(username, password) {
|
function setUserPass(username, password) {
|
||||||
window.sessionStorage.setItem(
|
let userpass = {username: username, password: password};
|
||||||
'userpass',
|
try {
|
||||||
JSON.stringify({username: username, password: password}),
|
window.sessionStorage.setItem('userpass', JSON.stringify(userpass));
|
||||||
);
|
fallbackUserPass = null;
|
||||||
|
} catch(e) {
|
||||||
|
console.warn("Couldn't store password:", e);
|
||||||
|
fallbackUserPass = {username: username, password: password};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserPass() {
|
function getUserPass() {
|
||||||
let userpass = window.sessionStorage.getItem('userpass');
|
let userpass;
|
||||||
if(!userpass)
|
try {
|
||||||
return null;
|
let json = window.sessionStorage.getItem('userpass');
|
||||||
return JSON.parse(userpass);
|
userpass = JSON.parse(json);
|
||||||
|
} catch(e) {
|
||||||
|
console.warn("Couldn't retrieve password:", e);
|
||||||
|
userpass = fallbackUserPass;
|
||||||
|
}
|
||||||
|
return userpass || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUsername() {
|
function getUsername() {
|
||||||
|
|
Loading…
Reference in a new issue