|
1 // //////////////////////////////////////////////////////////////////////////// |
|
2 // (c)2009 Symbian Foundation |
|
3 // //////////////////////////////////////////////////////////////////////////// |
|
4 |
|
5 |
|
6 // Login to the developer site |
|
7 |
|
8 var loginUrlContent = null; |
|
9 var loginUrlHttpReq = null; |
|
10 var loginCallback = null; |
|
11 |
|
12 function login(callback){ |
|
13 if ( forumUsername == null || forumPassword == null ) { |
|
14 loginInitiated = true; |
|
15 loginInitiatedCallback = callback; |
|
16 promptForPassword(); |
|
17 return; |
|
18 } |
|
19 loginCallback = callback; |
|
20 loginInitiated = false; |
|
21 loginInitiatedCallback = null; |
|
22 uiManager.showNotification(-1, "wait", "Please wait...", -1); |
|
23 |
|
24 var parameters = symbianOrgLoginUsernameField + "=" + forumUsername |
|
25 + "&" + symbianOrgLoginPasswordField + "=" + forumPassword |
|
26 + "&submit=Login&image_submit.x=0&image_submit.y=0&image_submit=submit" |
|
27 + "&referrer="+symbianOrgBaseUrl; |
|
28 loginUrlHttpReq = new Ajax(); |
|
29 loginUrlHttpReq.onreadystatechange = loginComplete; |
|
30 |
|
31 // initiate the request |
|
32 loginUrlHttpReq.open('POST', symbianOrgLoginUrl +"?referer="+symbianOrgBaseUrl, true); |
|
33 loginUrlHttpReq.setRequestHeader("Referer", symbianOrgBaseUrl); |
|
34 loginUrlHttpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
|
35 loginUrlHttpReq.setRequestHeader("Content-length", parameters.length); |
|
36 loginUrlHttpReq.setRequestHeader("Connection", "close"); |
|
37 loginUrlHttpReq.send(parameters); |
|
38 } |
|
39 |
|
40 function loginComplete(){ |
|
41 if ( loginUrlHttpReq == null ) { |
|
42 return; |
|
43 } |
|
44 // complete request? |
|
45 var readyState = loginUrlHttpReq.readyState; |
|
46 // attempt to get response status |
|
47 var responseStatus = null; |
|
48 try { |
|
49 responseStatus = loginUrlHttpReq.status; |
|
50 } catch (noStatusException) {} |
|
51 if (readyState == 4) { |
|
52 |
|
53 if (responseStatus < 300) { |
|
54 |
|
55 var content = loginUrlHttpReq.responseText; |
|
56 if (content.indexOf("LoginWelcome") == -1) { |
|
57 uiManager.showNotification(3000, "warning", "Login failed."); |
|
58 promptForPassword(); |
|
59 } |
|
60 else { |
|
61 uiManager.hideNotification(); |
|
62 if (loginCallback != null) { |
|
63 loginCallback.call(); |
|
64 } |
|
65 checkForSecurityToken("loginComplete", content); |
|
66 } |
|
67 } else if (responseStatus < 400) { |
|
68 // do nothing, this must be a redirect |
|
69 } else { |
|
70 uiManager.hideNotification(); |
|
71 uiManager.showNotification(3000, "warning", "Login failed."); |
|
72 promptForPassword(); |
|
73 } |
|
74 } |
|
75 } |
|
76 |