Backup user data to NativeStorage
This commit is contained in:
parent
675248dfd3
commit
9cb914512b
@ -33,6 +33,15 @@ function saveaccounts(accounts) {
|
|||||||
NativeStorage.setItem("accounts", JSON.stringify(accounts));
|
NativeStorage.setItem("accounts", JSON.stringify(accounts));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function recoveraccounts(callback) {
|
||||||
|
NativeStorage.getItem("accounts", function (data) {
|
||||||
|
localStorage.setItem("accounts", data);
|
||||||
|
callback(true);
|
||||||
|
}, function () {
|
||||||
|
callback(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch to a different account.
|
* Switch to a different account.
|
||||||
* @param {int} account The selected account index from localStorage.getItem('accounts')
|
* @param {int} account The selected account index from localStorage.getItem('accounts')
|
||||||
|
@ -204,7 +204,6 @@ function displayNotifications(callback) {
|
|||||||
$.post(localStorage.getItem("syncurl"), {
|
$.post(localStorage.getItem("syncurl"), {
|
||||||
username: localStorage.getItem("username"),
|
username: localStorage.getItem("username"),
|
||||||
key: localStorage.getItem("key"),
|
key: localStorage.getItem("key"),
|
||||||
password: localStorage.getItem("password"),
|
|
||||||
action: "checknotifications"
|
action: "checknotifications"
|
||||||
}, function (data) {
|
}, function (data) {
|
||||||
if (data.status === 'OK') {
|
if (data.status === 'OK') {
|
||||||
@ -312,11 +311,19 @@ document.addEventListener("deviceready", function () {
|
|||||||
minimumFetchInterval: 1,
|
minimumFetchInterval: 1,
|
||||||
stopOnTerminate: false,
|
stopOnTerminate: false,
|
||||||
startOnBoot: true,
|
startOnBoot: true,
|
||||||
forceReload: true
|
forceReload: false,
|
||||||
|
enableHeadless: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// Try to recover data from NativeStorage back to localStorage
|
||||||
|
recoveraccounts(function (ok) {
|
||||||
|
if (ok) {
|
||||||
|
restartApplication();
|
||||||
} else {
|
} else {
|
||||||
openscreen("setup1");
|
openscreen("setup1");
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
setTimeout(navigator.splashscreen.hide, 500);
|
setTimeout(navigator.splashscreen.hide, 500);
|
||||||
}, false);
|
}, false);
|
@ -75,6 +75,7 @@
|
|||||||
|
|
||||||
keys.push({"secret": key, "label": label, "issuer": issuer});
|
keys.push({"secret": key, "label": label, "issuer": issuer});
|
||||||
localStorage.setItem("otp", JSON.stringify(keys));
|
localStorage.setItem("otp", JSON.stringify(keys));
|
||||||
|
NativeStorage.setItem("otp", JSON.stringify(keys));
|
||||||
navigator.notification.alert("2-factor key saved.", null, "Key added", 'Dismiss');
|
navigator.notification.alert("2-factor key saved.", null, "Key added", 'Dismiss');
|
||||||
openscreen("otp");
|
openscreen("otp");
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,10 @@
|
|||||||
|
|
||||||
var totp = new jsOTP.totp();
|
var totp = new jsOTP.totp();
|
||||||
|
|
||||||
var ls_text = localStorage.getItem("otp");
|
function load(jsontext) {
|
||||||
var keys = [];
|
var keys = [];
|
||||||
if (ls_text !== null && ls_text != "") {
|
if (jsontext !== null && jsontext != "") {
|
||||||
var keys = JSON.parse(ls_text || "[]");
|
var keys = JSON.parse(jsontext || "[]");
|
||||||
if (keys.length > 0) {
|
if (keys.length > 0) {
|
||||||
$("#nokeys").css("display", "none");
|
$("#nokeys").css("display", "none");
|
||||||
}
|
}
|
||||||
@ -46,6 +46,18 @@
|
|||||||
+ "</div>");
|
+ "</div>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var ls_text = localStorage.getItem("otp");
|
||||||
|
if (ls_text === null || ls_text == "") {
|
||||||
|
// Recover from NativeStorage
|
||||||
|
NativeStorage.getItem("otp", function (data) {
|
||||||
|
localStorage.setItem("otp");
|
||||||
|
load(data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
load(ls_text);
|
||||||
|
}
|
||||||
|
|
||||||
function refreshCountdown() {
|
function refreshCountdown() {
|
||||||
var percent = ((30 - ((new Date).getSeconds() % 30)) / 30) * 100;
|
var percent = ((30 - ((new Date).getSeconds() % 30)) / 30) * 100;
|
||||||
|
@ -71,10 +71,12 @@
|
|||||||
localStorage.removeItem("syncurl");
|
localStorage.removeItem("syncurl");
|
||||||
localStorage.removeItem("key");
|
localStorage.removeItem("key");
|
||||||
localStorage.removeItem("accounts");
|
localStorage.removeItem("accounts");
|
||||||
|
NativeStorage.remove("accounts", function () {
|
||||||
// force-reload app
|
// force-reload app
|
||||||
navigator.notification.alert("All connection data and credentials erased.", function () {
|
navigator.notification.alert("All connection data and credentials erased.", function () {
|
||||||
restartApplication();
|
restartApplication();
|
||||||
}, "App Reset", 'Continue');
|
}, "App Reset", 'Continue');
|
||||||
|
});
|
||||||
}, "Are you sure?");
|
}, "Are you sure?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user