Merge pull request #984 from imachug/privatekey

Don't ask user for privatekey if file can be signed with auth_privatekey
This commit is contained in:
ZeroNet 2017-06-15 22:38:02 +02:00 committed by GitHub
commit 3489d5de09
2 changed files with 35 additions and 28 deletions

View file

@ -354,17 +354,18 @@ class Sidebar extends Class
@tag.find("#button-sign").off("click touchend").on "click touchend", => @tag.find("#button-sign").off("click touchend").on "click touchend", =>
inner_path = @tag.find("#input-contents").val() inner_path = @tag.find("#input-contents").val()
if wrapper.site_info.privatekey wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
# Privatekey stored in users.json if wrapper.site_info.privatekey or wrapper.site_info.auth_address in res.signers
wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: inner_path, update_changed_files: true}, (res) => # Privatekey stored in users.json
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000 wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: inner_path, update_changed_files: true}, (res) =>
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
else else
# Ask the user for privatekey # Ask the user for privatekey
wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key wrapper.displayPrompt "Enter your private key:", "password", "Sign", "", (privatekey) => # Prompt the private key
wrapper.ws.cmd "siteSign", {privatekey: privatekey, inner_path: inner_path, update_changed_files: true}, (res) => wrapper.ws.cmd "siteSign", {privatekey: privatekey, inner_path: inner_path, update_changed_files: true}, (res) =>
if res == "ok" if res == "ok"
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000 wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
return false return false

View file

@ -189,7 +189,8 @@ window.initScrollable = function () {
var Sidebar, var Sidebar,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty; hasProp = {}.hasOwnProperty,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Sidebar = (function(superClass) { Sidebar = (function(superClass) {
extend(Sidebar, superClass); extend(Sidebar, superClass);
@ -600,27 +601,32 @@ window.initScrollable = function () {
return function() { return function() {
var inner_path; var inner_path;
inner_path = _this.tag.find("#input-contents").val(); inner_path = _this.tag.find("#input-contents").val();
if (wrapper.site_info.privatekey) { wrapper.ws.cmd("fileRules", {
wrapper.ws.cmd("siteSign", { inner_path: inner_path
privatekey: "stored", }, function(res) {
inner_path: inner_path, var ref;
update_changed_files: true if (wrapper.site_info.privatekey || (ref = wrapper.site_info.auth_address, indexOf.call(res.signers, ref) >= 0)) {
}, function(res) {
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
});
} else {
wrapper.displayPrompt("Enter your private key:", "password", "Sign", "", function(privatekey) {
return wrapper.ws.cmd("siteSign", { return wrapper.ws.cmd("siteSign", {
privatekey: privatekey, privatekey: "stored",
inner_path: inner_path, inner_path: inner_path,
update_changed_files: true update_changed_files: true
}, function(res) { }, function(res) {
if (res === "ok") { return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
}
}); });
}); } else {
} return wrapper.displayPrompt("Enter your private key:", "password", "Sign", "", function(privatekey) {
return wrapper.ws.cmd("siteSign", {
privatekey: privatekey,
inner_path: inner_path,
update_changed_files: true
}, function(res) {
if (res === "ok") {
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
}
});
});
}
});
return false; return false;
}; };
})(this)); })(this));
@ -676,7 +682,7 @@ window.initScrollable = function () {
return img.onload = (function(_this) { return img.onload = (function(_this) {
return function() { return function() {
return wrapper.ws.cmd("sidebarGetPeers", [], function(globe_data) { return wrapper.ws.cmd("sidebarGetPeers", [], function(globe_data) {
var e, ref, ref1; var e, error, ref, ref1;
if (_this.globe) { if (_this.globe) {
_this.globe.scene.remove(_this.globe.points); _this.globe.scene.remove(_this.globe.points);
_this.globe.addData(globe_data, { _this.globe.addData(globe_data, {