mypackage_wrt/Login.js
changeset 44 48bcd0bbc1ab
parent 42 20be4dd42b12
--- a/mypackage_wrt/Login.js	Wed May 05 11:52:23 2010 +0100
+++ b/mypackage_wrt/Login.js	Thu May 06 13:01:45 2010 +0100
@@ -12,9 +12,12 @@
 var loginUrlContent = null;
 var loginUrlHttpReq = null;
 var loginCallback = null;
+var logincompleted=null;
+
 
 var isHideNotifications = true;
 function login(callback){
+	debuglog.debug("Starting login");
 	if ( forumUsername == null || forumPassword == null ) {
 		loginInitiated = true;
 		loginInitiatedCallback = callback;
@@ -24,6 +27,7 @@
 	loginCallback = callback;
 	loginInitiated = false;
 	loginInitiatedCallback = null;
+	//sflogout();
 	uiManager.showNotification(-1, "wait", "Please wait...", -1);	
 	
 	var parameters =  symbianOrgLoginUsernameField + "=" + forumUsername
@@ -32,6 +36,7 @@
 			  + "&referrer="+symbianOrgBaseUrl;
 	loginUrlHttpReq = new Ajax();
     loginUrlHttpReq.onreadystatechange = loginComplete;
+
 	
     // initiate the request
 	loginUrlHttpReq.open('POST', symbianOrgLoginUrl +"?referer="+symbianOrgBaseUrl, true);
@@ -42,7 +47,15 @@
 	loginUrlHttpReq.send(parameters);
 }
 
+function loginfailed(myerror){
+	debuglog.debug("login failed with error " + myerror);
+	uiManager.showNotification(2000, "warning", "Login failed "+ myerror);
+	isHideNotifications=false;
+	//promptForPassword();
+	
+}
 function loginComplete(){
+	debuglog.debug("login completed called");
 	if ( loginUrlHttpReq == null ) {
 		return;
 	}
@@ -54,13 +67,18 @@
         responseStatus = loginUrlHttpReq.status;
     } catch (noStatusException) {}
     if (readyState == 4) {
-
+		debuglog.debug("ready state found");
 		if (responseStatus < 300) {
 			
 			var content = loginUrlHttpReq.responseText;
+			if (content.indexOf("<title>Symbian developer community - log in</title>")!=-1) {
+				loginfailed("- Bad Credentials");
+				return;
+			}
+			
 			if (content.indexOf("LoginWelcome") == -1) {
-				uiManager.showNotification(3000, "warning", "Login failed.");
-				promptForPassword();
+				loginfailed(null);
+				return;
 			}
 			else {
 				if (loginCallback != null) {
@@ -72,15 +90,13 @@
 			    vbCookieGet.onreadystatechange = forumCookieHarvestComplete;
 				vbCookieGet.open('GET', vburl, true);
 				vbCookieGet.send(null);
-			}
+				}
 		} else if (responseStatus < 400) {
 			// do nothing, this must be a redirect
 		} else {
-			uiManager.hideNotification();
-			uiManager.showNotification(3000, "warning", "Login failed.");
-			promptForPassword();
+			loginfailed("- HTTP error " + responseStatus);
 		}
-    }
+    } 
 }
 
 function forumCookieHarvestComplete () {
@@ -88,4 +104,7 @@
 		uiManager.hideNotification();
 	}
 	isHideNotifications = true;
+	logincompleted=true;
+	debuglog.debug("cookie harvested");
 }
+