Commits

watermelon committed 3bcf1d9

implemented disconnect

  • Participants
  • Parent commits 037207b

Comments (0)

Files changed (3)

File src/main/client/controller/Controller.js

  * 
  * the logged in user's communicator to the server
  **/
-bookmaak.controller.Controller.communicator = "";
+bookmaak.controller.Controller.communicator = null;
 
 /**
  * bookmaak.controller.Controller.rng -> SecureRandom
 
 
 /**
- * bookmaak.controller.Controller.probeServer(String, Function)
+ * bookmaak.controller.Controller.connect(String, Function)
  * 
- * TODO maybe we should replace that by a real login
+ * Connects to the specified server.
  * 
  * **server_url** the url of the server to be probed<br/>
  * **callback**		Is called passing the result as argument.<br/>
  * 				msg: String, textual error message
  * 			};
  **/
-bookmaak.controller.Controller.probeServer = function(server_url, callback) {
+bookmaak.controller.Controller.connect = function(server_url, callback) {
 	
 	//work around for problem with opera... :(((((( about:config#UserPrefs|AllowFileXHTTPRequest does not work
 	if(jQuery.browser.opera) {
 		return;
 	}
 	
-	//probe server
+	//try to reach server
 	jQuery.ajax({
 		url: server_url,
 		aync: false,//we want to probe the server before proceeding TODO maybe we change the wohle process and make the login a real login...
 		timeout: bookmaak.AJAX_TIMEOUT_MS,
 		complete: function(jqXHR, textStatus) {
 			
-			//TODO for debuging
-//			console.debug(jqXHR);
-			
 			var server_name = jqXHR.getResponseHeader("Server");
-			console.debug("wenn hier["+server_name+"] Bookmaak steht ist alles gut");
+			console.debug("bookmaak.controller.Controller.connect: wenn hier["+server_name+"] Bookmaak steht ist alles gut");
 			
 			//TODO for now we decide only on status
 			console.debug("jqXHR.status: "+jqXHR.status);
 			if(jqXHR.status == 200 /*&& server_name == "Bookmaak"*/) {
-				console.info("Server is up!");
-				callback({
-					success: true,
-					type: "",
-					msg: ""
+				
+				console.info("bookmaak.controller.Controller.connect: Server is up!");
+				
+				//set the server url in Controller.
+				bookmaak.controller.Controller.server_url = server_url;
+				
+				callback({	success: true,
+							type: "",
+							msg: ""
 				});
 			}
 			else if(jqXHR.status == 0) {
-				console.error("Server is down!");
-				callback({
-					success: false,
-					type: "network error",
-					msg: "Server is not reachable!"
+				
+				console.error("bookmaak.controller.Controller.connect: Server is down!");
+				
+				callback({	success: false,
+							type: "network error",
+							msg: "Server is not reachable!"
 				});
 			}
 			else {
-				console.error("Server is down or broken!");
-				callback({
-					success: false,
-					type: textStatus,
-					msg: "Status "+jqXHR.status+" - Server is down or broken!"
+				
+				console.error("bookmaak.controller.Controller.connect: Server is down or broken!");
+				
+				callback({	success: false,
+							type: textStatus,
+							msg: "Status "+jqXHR.status+" - Server is down or broken!"
 				});
 			}
 		}
 	});
 };
 
+/**
+ * bookmaak.controller.Controller.disconnect()
+ * 
+ * Disconnects the controller.
+ **/
+bookmaak.controller.Controller.disconnect = function() {
+	
+	console.debug("bookmaak.controller.Controller.disconnect: logging out...");
+	bookmaak.controller.Controller.login_name = "";
+	bookmaak.controller.Controller.communicator = null;
+	
+	console.debug("bookmaak.controller.Controller.disconnect: closing connection...");
+	bookmaak.controller.Controller.server_url = "";
+};
+
+
+
+
+
 
 /**
  * bookmaak.controller.userExists(String, Function)
 		timeout: bookmaak.AJAX_TIMEOUT_MS,
 		complete: function(jqXHR, textStatus) {
 			
-			console.debug("userExists request complete. status: "+jqXHR.status+" textStatus: "+textStatus);
+			console.debug("bookmaak.controller.userExists: userExists request complete. status: "+jqXHR.status+" textStatus: "+textStatus);
 			
 			switch(jqXHR.status) {
 				case 302:
-					console.info("Status: "+jqXHR.status+" - User '"+login+"' exists!");
+					console.info("bookmaak.controller.userExists: Status: "+jqXHR.status+" - User '"+login+"' exists!");
 					callback({	exists: true,
 								type: "",
 								msg: "User \'"+login+"\' exists."
 					});
 					break;
 				case 404:
-					console.info("Status: "+jqXHR.status+" - User '"+login+"' does not exist!");
+					console.info("bookmaak.controller.userExists: Status: "+jqXHR.status+" - User '"+login+"' does not exist!");
 					callback({	exists: false,
 								type: "",
 								msg: "User \'"+login+"\' does not exist."
 					});
 					break;
 				default:
-					console.error("Status: "+jqXHR.status+" - Unexpected error!");
+					console.error("bookmaak.controller.userExists: Status: "+jqXHR.status+" - Unexpected error!");
 					callback({	exists: undefined,
 								type: textStatus,
 								msg: "An error occured during user existance request."
 bookmaak.controller.Controller.login = function(login, callback) {
 	
 	//init user's communicator
-	console.debug("Initializing user's communicator...");
+	console.debug("bookmaak.controller.Controller.login: Initializing user's communicator...");
 	bookmaak.controller.Controller.
 	communicator = new bookmaak.comm.
 						Communicator(
 							bookmaak.controller.Controller.server_url);
 	
 	//retrieve user file
-	console.debug("Trying to retrieve the user file...");
+	console.debug("bookmaak.controller.Controller.login: Trying to retrieve the user file...");
 	bookmaak.controller.Controller.
 	communicator.retrieveFile(
 		bookmaak.controller.FILE_TYPE.USER,
 //			msg: String, textual message, describing the error or success.
 //		}
 		if(result.success) {
-			console.log("Successfully retrieved user file!");
+			console.log("bookmaak.controller.Controller.login: Successfully retrieved user file!");
 			bookmaak.controller.Controller.login_name = login;
 		}
 		else {
-			console.error("Failed to retrieved user file!");
-			console.error("Error type: "+result.type+" Msg:"+result.msg);
+			console.error("bookmaak.controller.Controller.login: Failed to retrieved user file!");
+			console.error("bookmaak.controller.Controller.login: Error type: "+result.type+" Msg:"+result.msg);
 			//TODO maybe disconnect... if servers fault
 		}
 		callback(result.success);

File src/main/client/crypto/UserCrypto.js

 	/**
 	 * bookmaak.crypto.UserCrypto#encryptUserFile(File) -> File
 	 *
-	 * brauchen wir derzeit nicht... erst wenn wir den symmetrischen schl�ssel
-	 * �ndern wollen
+	 * brauchen wir derzeit nicht... erst wenn wir den symmetrischen schl�ssel
+	 * �ndern wollen
 	 *
 	 * **plain_file** the plain file.
 	 **/
 		//RSA decryption
 		var data_decrypted = rsa.decrypt(data_encrypted);
 		
-		//maybe we cancle that thought
+		//maybe we cancel that thought
 		//var userData = "";//find the only valid text, which is the users sym
 		//key, guard by [symKey] and [/symKey]
 		

File src/main/client/ui/connect_presenter.js

 bookmaak.ui.onClickConnect = function() {
 	
 	var _server_url = jQuery("#connect_to_url").val();
-	console.log("server url inupt:"+_server_url);
-	
+	console.log("bookmaak.ui.onClickConnect: server url inupt:"+_server_url);
 	
 	//validate server url
 	var server_url_is_valid = bookmaak.util.validation.validateServerUrl(_server_url);
 	if(server_url_is_valid) {//fix it if necessary
 		
 		_server_url = bookmaak.util.validation.fixServerUrl(_server_url);
-		console.log("server url fixed:"+_server_url);
+		console.log("bookmaak.ui.onClickConnect: server url fixed:"+_server_url);
 		
 		//try to contact server
-		bookmaak.controller.Controller.probeServer(_server_url, function(probe) {
+		bookmaak.controller.Controller.connect(_server_url, function(connection) {
 			
-			if(probe.success){
+			if(connection.success){
 				
 				var success_text = "Connection successful! "
-					+(probe.msg != "" ? "("+probe.msg+")" : "");
+					+(connection.msg != "" ? "("+connection.msg+")" : "");
 					
 				bookmaak.ui.printSuccessMessage(success_text);
 				
-				//set the server url in Controller.
-				bookmaak.controller.Controller.server_url = _server_url;
-				
 				showConnectViewConnected();
-				
 				showLoginView();
 			}
 			else {
 				
 				var error_text = "Connection failed! "
-					+(probe.type != "" ? "<br/>Error type: "+probe.type : "")
-					+(probe.msg ? " - "+probe.msg : "");
+					+(connection.type != "" ? "<br/>Error type: "+connection.type : "")
+					+(connection.msg ? " - "+connection.msg : "");
 					
 				bookmaak.ui.printErrorMessage(error_text);
 			}
  **/
 bookmaak.ui.onClickDisconnect = function() {
 	
-	//TODO destroy all crypto objects
+	bookmaak.controller.Controller.disconnect();
 	
 	showConnectViewDisconnected();
 };