changeset 2301:18d390c66b47

Addresses issue #35, though I am not sure if there are any side-effects
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 27 Apr 2016 20:44:00 +0100
parents a73495c6d604
children f7604317ac27
files js/core.js
diffstat 1 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/js/core.js	Wed Apr 27 21:50:33 2016 +0100
+++ b/js/core.js	Wed Apr 27 20:44:00 2016 +0100
@@ -2822,13 +2822,18 @@
         handleEvent: function() {
             var parse = new DOMParser();
             var xml = parse.parseFromString(this.request.response,"text/xml");
-            if (xml.getAllElementsByTagName("state")[0].textContent == "OK") {
-                this.key = xml.getAllElementsByTagName("key")[0].textContent;
-                this.parent.root.setAttribute("key",this.key);
-                this.parent.root.setAttribute("state","empty");
-            } else {
-                this.generateKey();
-            }
+            var shouldGenerateKey = true;
+            if(xml.getAllElementsByTagName("state").length > 0){
+				if (xml.getAllElementsByTagName("state")[0].textContent == "OK") {
+					this.key = xml.getAllElementsByTagName("key")[0].textContent;
+					this.parent.root.setAttribute("key",this.key);
+					this.parent.root.setAttribute("state","empty");
+					shouldGenerateKey = false;
+				}
+			}
+			if(shouldGenerateKey === true){
+				this.generateKey();
+			}
         },
         generateKey: function() {
             var temp_key = randomString(32);