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 {
|
} else {
|
||||||
openscreen("setup1");
|
// Try to recover data from NativeStorage back to localStorage
|
||||||
|
recoveraccounts(function (ok) {
|
||||||
|
if (ok) {
|
||||||
|
restartApplication();
|
||||||
|
} else {
|
||||||
|
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,25 +26,37 @@
|
|||||||
|
|
||||||
var totp = new jsOTP.totp();
|
var totp = new jsOTP.totp();
|
||||||
|
|
||||||
|
function load(jsontext) {
|
||||||
|
var keys = [];
|
||||||
|
if (jsontext !== null && jsontext != "") {
|
||||||
|
var keys = JSON.parse(jsontext || "[]");
|
||||||
|
if (keys.length > 0) {
|
||||||
|
$("#nokeys").css("display", "none");
|
||||||
|
}
|
||||||
|
for (var i = 0; i < keys.length; i++) {
|
||||||
|
var code = totp.getOtp(keys[i]["secret"]);
|
||||||
|
// Escape HTML characters
|
||||||
|
var label = $('<div/>').html(keys[i]["label"]).html();
|
||||||
|
var issuer = $('<div/>').text(keys[i]["issuer"]).html();
|
||||||
|
$("#codelist").append("<div class=\"list-group-item\" id=\"codeitem_" + i + "\">"
|
||||||
|
+ "<span class=\"pull-right\" style=\"color: red;\" onclick=\"deleteCode(" + i + ")\"><i class=\"fa fa-trash-o\"></i></span>"
|
||||||
|
+ "<p class=\"h6\">" + label + "</p>"
|
||||||
|
+ "<div class=\"h3 code\" style=\"font-weight: bold;\">" + code + "</div>"
|
||||||
|
+ "<p class=\"small\">" + issuer + "</p>"
|
||||||
|
+ "</div>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var ls_text = localStorage.getItem("otp");
|
var ls_text = localStorage.getItem("otp");
|
||||||
var keys = [];
|
if (ls_text === null || ls_text == "") {
|
||||||
if (ls_text !== null && ls_text != "") {
|
// Recover from NativeStorage
|
||||||
var keys = JSON.parse(ls_text || "[]");
|
NativeStorage.getItem("otp", function (data) {
|
||||||
if (keys.length > 0) {
|
localStorage.setItem("otp");
|
||||||
$("#nokeys").css("display", "none");
|
load(data);
|
||||||
}
|
});
|
||||||
for (var i = 0; i < keys.length; i++) {
|
} else {
|
||||||
var code = totp.getOtp(keys[i]["secret"]);
|
load(ls_text);
|
||||||
// Escape HTML characters
|
|
||||||
var label = $('<div/>').html(keys[i]["label"]).html();
|
|
||||||
var issuer = $('<div/>').text(keys[i]["issuer"]).html();
|
|
||||||
$("#codelist").append("<div class=\"list-group-item\" id=\"codeitem_" + i + "\">"
|
|
||||||
+ "<span class=\"pull-right\" style=\"color: red;\" onclick=\"deleteCode(" + i + ")\"><i class=\"fa fa-trash-o\"></i></span>"
|
|
||||||
+ "<p class=\"h6\">" + label + "</p>"
|
|
||||||
+ "<div class=\"h3 code\" style=\"font-weight: bold;\">" + code + "</div>"
|
|
||||||
+ "<p class=\"small\">" + issuer + "</p>"
|
|
||||||
+ "</div>");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshCountdown() {
|
function refreshCountdown() {
|
||||||
|
@ -71,10 +71,12 @@
|
|||||||
localStorage.removeItem("syncurl");
|
localStorage.removeItem("syncurl");
|
||||||
localStorage.removeItem("key");
|
localStorage.removeItem("key");
|
||||||
localStorage.removeItem("accounts");
|
localStorage.removeItem("accounts");
|
||||||
// force-reload app
|
NativeStorage.remove("accounts", function () {
|
||||||
navigator.notification.alert("All connection data and credentials erased.", function () {
|
// force-reload app
|
||||||
restartApplication();
|
navigator.notification.alert("All connection data and credentials erased.", function () {
|
||||||
}, "App Reset", 'Continue');
|
restartApplication();
|
||||||
|
}, "App Reset", 'Continue');
|
||||||
|
});
|
||||||
}, "Are you sure?");
|
}, "Are you sure?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user