profile download implemented; closes #16
This commit is contained in:
@@ -24,10 +24,7 @@
|
||||
|
||||
<ul id="menu" style="display: none">
|
||||
<li onclick="backup()">Download Backup</li>
|
||||
<li>
|
||||
<label for="restore">Restore: Upload Backup</label>
|
||||
<input autocomplete="off" type="file" accept="text/*" id="restore" />
|
||||
</li>
|
||||
<li class="toolbutton"><label for="restore">Restore Backup</label><input autocomplete="off" type="file" accept="text/*" id="restore" /></li>
|
||||
</ul>
|
||||
<script>
|
||||
$("#restore").change(function(evt){restore(evt)});
|
||||
|
@@ -121,9 +121,10 @@ td:last-child {
|
||||
list-style-type: none;
|
||||
border: 1px solid black;
|
||||
}
|
||||
#menu li {
|
||||
#menu li, #menu li * {
|
||||
padding: 0 1em 0 1em;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
#menu li + li {
|
||||
border-top: 1px solid black;
|
||||
|
@@ -139,7 +139,7 @@ function togglemenu() {
|
||||
|
||||
/// Download Profile Backup
|
||||
function backup() {
|
||||
status("<p>Starting Download...</p>");
|
||||
status("<p>Starting backup download ...</p>");
|
||||
var download = document.createElement('a');
|
||||
download.href = 'data:attachment/text,'+encodeURI(JSON.stringify(localStorage));
|
||||
download.target = '_blank';
|
||||
@@ -155,11 +155,29 @@ function backup() {
|
||||
});
|
||||
download.dispatchEvent(clickEvent);
|
||||
togglemenu();
|
||||
setTimeout(start, 20000);
|
||||
setTimeout(start, 2000);
|
||||
}
|
||||
|
||||
/// Upload Profile Backup
|
||||
function restore(evt) {
|
||||
status("<p>Starting backup restore ...</p>");
|
||||
if (!window.FileReader)
|
||||
return error("your browser dows not support file upload", true);
|
||||
for (var i=0, f; f=evt.target.files[i]; ++i) {
|
||||
var file = f;
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(evt) {
|
||||
if (evt.target.error) return error("error reading file", true);
|
||||
if (evt.target.readyState==0) return notice("waiting for data ...");
|
||||
if (evt.target.readyState==1) return notice("loading data ...");
|
||||
var parsed=JSON.parse(evt.target.result);
|
||||
togglemenu();
|
||||
localStorage.pubKey = parsed.pubKey;
|
||||
localStorage.privKey = parsed.privKey;
|
||||
setTimeout(start, 2000);
|
||||
}
|
||||
reader.readAsText(file);
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if user name is available
|
||||
@@ -251,8 +269,8 @@ function createkeypair(user, pwd) {
|
||||
passphrase: pwd
|
||||
}).then(function(keyPair) {
|
||||
success("keys generated");
|
||||
localStorage.pubKey = keyPair.publicKeyArmored;
|
||||
localStorage.privKey = keyPair.privateKeyArmored;
|
||||
localStorage["pubKey"] = keyPair.publicKeyArmored;
|
||||
localStorage["privKey"] = keyPair.privateKeyArmored;
|
||||
login();
|
||||
}).catch(function(e) {
|
||||
error(e);
|
||||
@@ -262,15 +280,15 @@ function createkeypair(user, pwd) {
|
||||
/// Get Own Public Key
|
||||
/** @return public key object */
|
||||
function publicKey() {
|
||||
if (typeof localStorage.pubKey == 'undefined') return null;
|
||||
return openpgp.key.readArmored(localStorage.pubKey);
|
||||
if (typeof localStorage["pubKey"] == 'undefined') return null;
|
||||
return openpgp.key.readArmored(localStorage["pubKey"]);
|
||||
}
|
||||
|
||||
/// Get Own Private Key
|
||||
/** @return private key object */
|
||||
function privateKey() {
|
||||
if (typeof localStorage.privKey == 'undefined') return null;
|
||||
return openpgp.key.readArmored(localStorage.privKey);
|
||||
if (typeof localStorage["privKey"] == 'undefined') return null;
|
||||
return openpgp.key.readArmored(localStorage["privKey"]);
|
||||
}
|
||||
|
||||
/// Get Own User Name
|
||||
|
Reference in New Issue
Block a user