Commits

watermelon committed 26877ad

fixed registration bug, improved server_url recognition, messages are now displayed longer

Comments (0)

Files changed (5)

src/main/client/controller/Controller.js

  * 
  * **_server_url**	The (new) url to the server.
  * 					If non is specified, the previous will be used.
- * 					If it was never set, an exception is thrown.
- * **callback**		Is called passing the result as argument.
+ * 					If it was never set, an exception is thrown.<br/>
+ * **callback**		Is called passing the result as argument.<br/>
  * returns	calls callback with a result as
  * 			{	
  * 				success: Boolean, true on success, else false
 	//if a new url should be set
 	if(typeof _server_url != 'undefined') {
 		
-		if(Object.prototype.toString.call(_server_url) == "[object String]")
-			bookmaak.controller.Controller.server_url = _server_url;
+		if(Object.prototype.toString.call(_server_url) == "[object String]") {
+			
+			console.log("server url inupt:"+_server_url);
+			re_fix_url = /^(?:http:\/\/){0,1}(.+)(?:\/){0,1}$/;
+			bookmaak.controller.Controller.server_url = _server_url.replace(re_fix_url, "http://$1/");
+			console.log("server url fixed:"+bookmaak.controller.Controller.server_url);
+		}
 		else
 			throw "illegal argument _server_url.";
 	}
 		aync: false,
 		type: "HEAD",
 		crossDomain: true,
-		success: function(data, textStatus, jqXHR) {
+		complete: function(jqXHR, textStatus) {
 			
-			switch(jqXHR.status == 302) {
+			console.debug("userExists request complete. status: "+jqXHR.status+" textStatus: "+textStatus);
+			
+			switch(jqXHR.status) {
 				
 				case 302:
+					console.info("Status: "+jqXHR.status+" - User '"+login+"' exists!");
 					callback({
 						exists: true,
 						type: "",
 					break;
 				
 				case 404:
+					console.info("Status: "+jqXHR.status+" - User '"+login+"' does not exist!");
 					callback({
 						exists: false,
 						type: "",
 					break;
 					
 				default:
+					console.error("Status: "+jqXHR.status+" - Unexpected error!");
 					callback({
 						exists: undefined,
 						type: textStatus,
 					});
 			}
 			return;
-		},
-		error: function(jqXHR, textStatus, errorThrown) {
-			
-			switch(textStatus) {
-			
-				case "abort":
-				case "parsererror":
-				case "timeout":
-					callback({
-						exists: undefined,
-						type: textStatus,
-						msg: ""
-					});
-					break;
-					
-				case "error":
-					//XXX thats the case at least for ff8 and ch16.0.912.63
-					if(jqXHR.status == 0) {
-						callback({
-							exists: undefined,
-							type: textStatus,
-							msg: "Server did not respond."
-						});
-					}
-					else {	
-						callback({
-							exists: undefined,
-							type: textStatus,
-							msg: errorThrown
-						});
-					}
-					break;
-					
-				default:
-					callback({
-						exists: undefined,
-						type: textStatus,
-						msg: "unhandled response status"
-					});
-			}
-			return;
 		}
 	});
 };
  * 		rsa_private_key_pem: the private key
  * 		rsa_public_key_pem: the public key
  * }
- * **callback** callback, passsing result
+ * **callback** callback, passsing result<br/>
  * returns	calls callback with a result as
  * 		{	
  * 			success: Boolean, true on success, else false
 	bookmaak.controller.Controller.rng.nextBytes(symm_key_bytes);
 	
 	var symm_key = pidCryptUtil.byteArray2String(symm_key_bytes);
-	alert("symm_key_b64: " + symm_key.encodeBase64());
 	
 	//create user file with symm key + filename (what will be the file name for this one... maybe the rsa encrypted user identification)
 	var user_file_plain = new bookmaak.domain.File(
 						if(result.success) {
 							
 							//save params to localstore TODO check results
-							bookmaak.controller.Controller.addSetting(
+							bookmaak.util.addSetting(
 									registrationData.login,
-									bookmaak.controller.SETTING_KEY.LOGIN,
-									registrationData.login);
+									bookmaak.util.SETTING_KEY.LOGIN,
+									registrationData.login,
+									bookmaak.util.SETTING_TYPE.USER);
 							
-							bookmaak.controller.Controller.addSetting(
+							bookmaak.util.addSetting(
 									registrationData.login,
-									bookmaak.controller.SETTING_KEY.PRIVATE_KEY,
-									registrationData.rsa_private_key_pem);
+									bookmaak.util.SETTING_KEY.PRIVATE_KEY,
+									registrationData.rsa_private_key_pem,
+									bookmaak.util.SETTING_TYPE.USER);
 							
-							bookmaak.controller.Controller.addSetting(
+							bookmaak.util.addSetting(
 									registrationData.login,
-									bookmaak.controller.SETTING_KEY.PUBLIC_KEY,
-									registrationData.rsa_public_key_pem);
+									bookmaak.util.SETTING_KEY.PUBLIC_KEY,
+									registrationData.rsa_public_key_pem,
+									bookmaak.util.SETTING_TYPE.USER);
 							
 							callback(result);
 						}

src/main/client/ui/UiController.js

 	jQuery(elem).html(message);
 	
 	//show message
-	jQuery(elem).fadeIn(1000);
+	jQuery(elem).fadeIn(500);
 	
 	//fade it out again
 	setTimeout(function(){
 		
-		jQuery(elem).fadeOut("slow", function () {
-			
-			jQuery(elem).hide();
-		});
-	}, 1500);
+		jQuery(elem).fadeOut();
+//		"slow", function () {
+//			
+//			jQuery(elem).hide();
+//		}
+	}, 2000);
 };
 
 
 		var login = _login;
 	}
 	
-	console.log("login does not yet exist: "+!login_exists);
+	console.log("login does not exist: "+!login_exists);
 	console.log("login is valid: "+login_is_valid);
 	
 	

src/main/client/ui/register_view.jade

   label(for='register_private_key')
     | Paste your private encrypted rsa key:
   br
-  textarea#register_private_key(rows=30 , cols=62)
+  textarea#register_private_key(rows=30 , cols=63)
   br
   br
   label(for='register_public_key')
     | Paste your public rsa key:
   br
-  textarea#register_public_key(rows=10 , cols=62)
+  textarea#register_public_key(rows=10 , cols=63)
   br
   br
   input(value='Register', type='button',

src/main/client/util/Settings.js

 	else
 		var value = _value;
 	
-	return addSetting(tpye, key+"_"+login, value);
+	return addSetting(type, key+"_"+login, value);
 };
 
 /**

src/main/server/srv.js

  *
 **/
 function respond_404(res,msg){
+	
+	console.log("responding 404");
+	
   res.writeHead(404,default_header({'Content-Type': 'text/plain'}));
   if(!msg){
     res.end('404 - Not found');
 **/
 function respond_302(res,msg){
 	
+	console.log("responding 302");
+	
 	res.writeHead(302,default_header({'Content-Type': 'text/plain'}));
 	
 	if(!msg) {
  *
 **/
 function err_500(res,msg){
+	
+	console.log("responding 500");
+	
   res.writeHead(500,default_header({'Content-Type': 'text/plain'}));
   if(!msg){
     res.end('500 - internal error');
  *
 **/
 function err_501(res,msg){
+	
+	console.log("responding 501");
+		
   res.writeHead(501,default_header({'Content-Type': 'text/plain'}));
   if(!msg){
     res.end('501 - not implemented');
 **/
 function err_406(res,msg) {
 	
+	console.log("responding 406");
+	
 	res.writeHead(406,default_header({'Content-Type': 'text/plain'}));
 	
 	if(!msg)
 **/
 function err_507(res,msg) {
 	
+	console.log("responding 507");
+	
 	res.writeHead(507,default_header({'Content-Type': 'text/plain'}));
 	
 	if(!msg)
  */
 function doesUserExist(req, res, user_path) {
 	
-	console.log('doesUserExist('+rel_path+')');
+	console.log('doesUserExist('+user_path+')');
 	
 	//alternative
 //	path.exists(
 //			});
 	
 	fs.stat(BASE_DIR + user_path,
-			function(status, stats) {
+			function(err, stats) {
 				
-				console.log("stats.isFile(): "+stats.isFile());
-				console.log("stats.isDirectory(): "+stats.isDirectory());
-				var username = user_path.substring(1);
-				
-				if(stats.isDirectory()) {
+				if(err && err.errno == 34 && err.code == 'ENOENT') {//user does not exist...
 					
-					respond_302(res,"User \'"+username+"\' exits.");
+					respond_404(res);
 				}
-				else {
+				else if(err) {//an other error
 					
-					respond_404(res, "User \'"+username+"\' does not exist.");
+					console.log("Unexpected error!");
+					console.log(err);
+					throw err;
+				}
+				else {//user exists
+					console.log("stats.isFile(): "+stats.isFile());
+					console.log("stats.isDirectory(): "+stats.isDirectory());
+					
+					var username = user_path.substring(1);
+					
+					if(stats.isDirectory()) {
+						
+						respond_302(res,"User \'"+username+"\' exits.");
+					}
+					else {
+						
+						throw "it seems you have a single file '"+username+"' in your .boomarks";
+					}
+
 				}
 			});
 }
 				res.writeHead(200,default_header({'Content-Type': 'text/plain'}));
 				res.end(data);
 			}else{
+				
 				respond_404(res, 'index.html missing!');
 			}
 		});