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