comparison js/core.js @ 2578:bf17cc19c1c0

Merge branch 'master' into Dev_main
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Mon, 24 Oct 2016 11:23:02 +0100
parents 249a1152e525 22673a6cfcfb
children d83b38564fbb c0854362d09d
comparison
equal deleted inserted replaced
2577:522f58e7773e 2578:bf17cc19c1c0
3125 this.state = 0; 3125 this.state = 0;
3126 3126
3127 this.initialise = function (existingStore) { 3127 this.initialise = function (existingStore) {
3128 if (existingStore == undefined) { 3128 if (existingStore == undefined) {
3129 // We need to get the sessionKey 3129 // We need to get the sessionKey
3130 this.SessionKey.generateKey(); 3130 this.SessionKey.requestKey();
3131 this.document = document.implementation.createDocument(null, "waetresult", null); 3131 this.document = document.implementation.createDocument(null, "waetresult", null);
3132 this.root = this.document.childNodes[0]; 3132 this.root = this.document.childNodes[0];
3133 var projectDocument = specification.projectXML; 3133 var projectDocument = specification.projectXML;
3134 projectDocument.setAttribute('file-name', url); 3134 projectDocument.setAttribute('file-name', url);
3135 projectDocument.setAttribute('url', qualifyURL(url)); 3135 projectDocument.setAttribute('url', qualifyURL(url));
3154 request: new XMLHttpRequest(), 3154 request: new XMLHttpRequest(),
3155 parent: this, 3155 parent: this,
3156 handleEvent: function () { 3156 handleEvent: function () {
3157 var parse = new DOMParser(); 3157 var parse = new DOMParser();
3158 var xml = parse.parseFromString(this.request.response, "text/xml"); 3158 var xml = parse.parseFromString(this.request.response, "text/xml");
3159 var shouldGenerateKey = true;
3160 if (this.request.response.length == 0) { 3159 if (this.request.response.length == 0) {
3161 console.log("Error: Server did not respond"); 3160 console.error("An unspecified error occured, no server key could be generated");
3162 return; 3161 return;
3163 } 3162 }
3164 if (xml.getElementsByTagName("state").length > 0) { 3163 if (xml.getElementsByTagName("state").length > 0) {
3165 if (xml.getElementsByTagName("state")[0].textContent == "OK") { 3164 if (xml.getElementsByTagName("state")[0].textContent == "OK") {
3166 this.key = xml.getAllElementsByTagName("key")[0].textContent; 3165 this.key = xml.getAllElementsByTagName("key")[0].textContent;
3167 this.parent.root.setAttribute("key", this.key); 3166 this.parent.root.setAttribute("key", this.key);
3168 this.parent.root.setAttribute("state", "empty"); 3167 this.parent.root.setAttribute("state", "empty");
3169 shouldGenerateKey = false; 3168 this.update();
3170 } 3169 return;
3171 } 3170 } else if (xml.getElementsByTagName("state")[0].textContent == "ERROR") {
3172 if (shouldGenerateKey === true) { 3171 this.key = null;
3173 this.generateKey(); 3172 console.error("Could not generate server key. Server responded with error message: \"" + xml.getElementsByTagName("message")[0].textContent + "\"");
3174 } 3173 return;
3174 }
3175 }
3176 this.key = null;
3177 console.error("An unspecified error occured, no server key could be generated");
3175 }, 3178 },
3176 generateKey: function () { 3179 requestKey: function () {
3177 var temp_key = randomString(32); 3180 // For new servers, request a new key from the server
3178 var returnURL = ""; 3181 var returnURL = "";
3179 if (typeof specification.projectReturn == "string") { 3182 if (typeof specification.projectReturn == "string") {
3180 if (specification.projectReturn.substr(0, 4) == "http") { 3183 if (specification.projectReturn.substr(0, 4) == "http") {
3181 returnURL = specification.projectReturn; 3184 returnURL = specification.projectReturn;
3182 } 3185 }
3183 } 3186 }
3184 this.request.open("GET", returnURL + "php/keygen.php?key=" + temp_key, true); 3187 this.request.open("GET", returnURL + "php/requestKey.php", true);
3185 this.request.addEventListener("load", this); 3188 this.request.addEventListener("load", this);
3186 this.request.send(); 3189 this.request.send();
3187 }, 3190 },
3188 update: function () { 3191 update: function () {
3189 if (this.key == null) { 3192 if (this.key == null) {