From 9bb0a0d91b38c15bcda81676ca41b85abe187079 Mon Sep 17 00:00:00 2001 From: HelloZeroNet Date: Sat, 9 Apr 2016 19:49:12 +0200 Subject: [PATCH] Display confirmation if zeroid already exists --- src/Ui/UiWebsocket.py | 17 +++++++++++++++++ src/Ui/media/Wrapper.coffee | 7 ++++++- src/Ui/media/all.js | 13 ++++++++++++- src/User/User.py | 9 +++++---- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Ui/UiWebsocket.py b/src/Ui/UiWebsocket.py index f9eebef7..cc3c549d 100644 --- a/src/Ui/UiWebsocket.py +++ b/src/Ui/UiWebsocket.py @@ -477,11 +477,28 @@ class UiWebsocket(object): ["done", "New certificate added: %s/%s@%s." % (auth_type, auth_user_name, domain)] ) self.response(to, "ok") + elif res is False: + # Display confirmation of change + cert_current = self.user.certs[domain] + body = "You current certificate: %s/%s@%s" % (cert_current["auth_type"], cert_current["auth_user_name"], domain) + #body += "
Do you want to change it to: %s/%s@%s?" % (auth_type, auth_user_name, domain) + self.cmd("confirm", [body, "Change it to %s/%s@%s" % (auth_type, auth_user_name, domain)], + lambda (res): self.cbCertAddConfirm(to, domain, auth_type, auth_user_name, cert) + ) else: self.response(to, "Not changed") except Exception, err: self.response(to, {"error": err.message}) + def cbCertAddConfirm(self, to, domain, auth_type, auth_user_name, cert): + self.user.deleteCert(domain) + self.user.addCert(self.user.getAuthAddress(self.site.address), domain, auth_type, auth_user_name, cert) + self.cmd( + "notification", + ["done", "Certificate changed to: %s/%s@%s." % (auth_type, auth_user_name, domain)] + ) + self.response(to, "ok") + # Select certificate for site def actionCertSelect(self, to, accepted_domains=[]): accounts = [] diff --git a/src/Ui/media/Wrapper.coffee b/src/Ui/media/Wrapper.coffee index 3e7869d1..7a58d67f 100644 --- a/src/Ui/media/Wrapper.coffee +++ b/src/Ui/media/Wrapper.coffee @@ -56,6 +56,9 @@ class Wrapper else if cmd == "prompt" # Prompt input @displayPrompt message.params[0], message.params[1], message.params[2], (res) => @ws.response message.id, res + else if cmd == "confirm" # Confirm action + @displayConfirm message.params[0], message.params[1], (res) => + @ws.response message.id, res else if cmd == "setSiteInfo" @sendInner message # Pass to inner frame if message.params.address == @address # Current page @@ -173,7 +176,9 @@ class Wrapper displayConfirm: (message, caption, cb) -> body = $(""+message+"") button = $("#{caption}") # Add confirm button - button.on "click", cb + button.on "click", => + cb(true) + return false body.append(button) @notifications.add("notification-#{caption}", "ask", body) diff --git a/src/Ui/media/all.js b/src/Ui/media/all.js index 8e5e3325..cdedfec6 100644 --- a/src/Ui/media/all.js +++ b/src/Ui/media/all.js @@ -830,6 +830,12 @@ jQuery.extend( jQuery.easing, return _this.ws.response(message.id, res); }; })(this)); + } else if (cmd === "confirm") { + return this.displayConfirm(message.params[0], message.params[1], (function(_this) { + return function(res) { + return _this.ws.response(message.id, res); + }; + })(this)); } else if (cmd === "setSiteInfo") { this.sendInner(message); if (message.params.address === this.address) { @@ -972,7 +978,12 @@ jQuery.extend( jQuery.easing, var body, button; body = $("" + message + ""); button = $("" + caption + ""); - button.on("click", cb); + button.on("click", (function(_this) { + return function() { + cb(true); + return false; + }; + })(this)); body.append(button); this.notifications.add("notification-" + caption, "ask", body); button.focus(); diff --git a/src/User/User.py b/src/User/User.py index fe9f7848..a81e8d8d 100644 --- a/src/User/User.py +++ b/src/User/User.py @@ -110,10 +110,7 @@ class User(object): } # Check if we have already cert for that domain and its not the same if self.certs.get(domain) and self.certs[domain] != cert_node: - raise Exception( - "You already have certificate for this domain: %s/%s@%s" % - (self.certs[domain]["auth_type"], self.certs[domain]["auth_user_name"], domain) - ) + return False elif self.certs.get(domain) == cert_node: # Same, not updated return None else: # Not exist yet, add @@ -121,6 +118,10 @@ class User(object): self.save() return True + # Remove cert from user + def deleteCert(self, domain): + del self.certs[domain] + # Set active cert for a site def setCert(self, address, domain): site_data = self.getSiteData(address)