Skip to content

Commit

Permalink
Don't ask user for privatekey if file can be signed with auth_privatekey
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesyringa committed Jun 15, 2017
1 parent a89f66e commit f4a0400
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
21 changes: 11 additions & 10 deletions plugins/Sidebar/media/Sidebar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,18 @@ class Sidebar extends Class
@tag.find("#button-sign").off("click touchend").on "click touchend", =>
inner_path = @tag.find("#input-contents").val()

if wrapper.site_info.privatekey
# Privatekey stored in users.json
wrapper.ws.cmd "siteSign", {privatekey: "stored", inner_path: inner_path, update_changed_files: true}, (res) =>
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
wrapper.ws.cmd "fileRules", {inner_path: inner_path}, (res) =>
if wrapper.site_info.privatekey or wrapper.site_info.auth_address in res.signers
# Privatekey stored in users.json
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
# Ask the user for privatekey
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) =>
if res == "ok"
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
else
# Ask the user for privatekey
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) =>
if res == "ok"
wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000

return false

Expand Down
42 changes: 24 additions & 18 deletions plugins/Sidebar/media/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ window.initScrollable = function () {
var Sidebar,
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; },
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) {
extend(Sidebar, superClass);
Expand Down Expand Up @@ -600,27 +601,32 @@ window.initScrollable = function () {
return function() {
var inner_path;
inner_path = _this.tag.find("#input-contents").val();
if (wrapper.site_info.privatekey) {
wrapper.ws.cmd("siteSign", {
privatekey: "stored",
inner_path: inner_path,
update_changed_files: true
}, function(res) {
return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
});
} else {
wrapper.displayPrompt("Enter your private key:", "password", "Sign", "", function(privatekey) {
wrapper.ws.cmd("fileRules", {
inner_path: inner_path
}, function(res) {
var ref;
if (wrapper.site_info.privatekey || (ref = wrapper.site_info.auth_address, indexOf.call(res.signers, ref) >= 0)) {
return wrapper.ws.cmd("siteSign", {
privatekey: privatekey,
privatekey: "stored",
inner_path: inner_path,
update_changed_files: true
}, 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;
};
})(this));
Expand Down Expand Up @@ -676,7 +682,7 @@ window.initScrollable = function () {
return img.onload = (function(_this) {
return function() {
return wrapper.ws.cmd("sidebarGetPeers", [], function(globe_data) {
var e, ref, ref1;
var e, error, ref, ref1;
if (_this.globe) {
_this.globe.scene.remove(_this.globe.points);
_this.globe.addData(globe_data, {
Expand Down

0 comments on commit f4a0400

Please sign in to comment.