Mercurial > rlmcintyre
comparison BoosterPack/logintets/.svn/text-base/login_controller.js.svn-base @ 0:0d795f02a8bb tip
initial committ. what was I thinking?
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 27 Sep 2010 16:57:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0d795f02a8bb |
---|---|
1 // js handling the login procedures | |
2 | |
3 // constants | |
4 var NORMAL_STATE = 4; | |
5 var LOGIN_PREFIX = 'login.php?'; | |
6 | |
7 // variables | |
8 var http = getHTTPObject(); // We create the HTTP Object | |
9 var hasSeed = false; | |
10 var loggedIn = false; | |
11 var seed_id = 0; | |
12 var seed = 0; | |
13 var fullname = ''; | |
14 var messages = ''; | |
15 | |
16 // getSeed method: gets a seed from the server for this transaction | |
17 function getSeed() | |
18 { // only get a seed if we're not logged in and we don't already have one | |
19 if (!loggedIn && !hasSeed) { | |
20 // open up the path | |
21 http.open('GET', LOGIN_PREFIX + 'task=getseed', true); | |
22 http.onreadystatechange = handleHttpGetSeed; | |
23 http.send(null); | |
24 } | |
25 } | |
26 | |
27 // handleHttpGetSeed method: called when the seed is returned from the server | |
28 function handleHttpGetSeed() | |
29 { | |
30 // if there hasn't been any errors | |
31 if (http.readyState == NORMAL_STATE) { | |
32 // split by the divider | | |
33 results = http.responseText.split('|'); | |
34 | |
35 // id is the first element | |
36 seed_id = results[0]; | |
37 | |
38 // seed is the second element | |
39 seed = results[1]; | |
40 | |
41 // now we have the seed | |
42 hasSeed = true; | |
43 } | |
44 } | |
45 | |
46 // validateLogin method: validates a login request | |
47 function validateLogin() | |
48 { | |
49 // ignore request if we are already logged in | |
50 if (loggedIn) | |
51 return; | |
52 | |
53 // get form form elements 'username' and 'password' | |
54 username = document.getElementById('username').value; | |
55 password = document.getElementById('password').value; | |
56 | |
57 // ignore if either is empty | |
58 if (username != '' && password != '') { | |
59 // compute the hash of the hash of the password and the seed | |
60 hash = hex_md5(hex_md5(password) + seed); | |
61 | |
62 // open the http connection | |
63 http.open('GET', LOGIN_PREFIX + 'task=checklogin&username='+username+'&id='+seed_id+'&hash='+hash, true); | |
64 | |
65 // where to go | |
66 http.onreadystatechange = handleHttpValidateLogin; | |
67 http.send(null); | |
68 } | |
69 } | |
70 | |
71 // handleHttpValidateLogin method: called when the validation results are returned from the server | |
72 function handleHttpValidateLogin() | |
73 { | |
74 // did the connection work? | |
75 if (http.readyState == NORMAL_STATE) { | |
76 // split by the pipe | |
77 results = http.responseText.split('|'); | |
78 if (results[0] == 'true') | |
79 { | |
80 hasSeed = false; | |
81 loggedIn = true; | |
82 fullname = results[1]; | |
83 messages = ''; | |
84 } | |
85 else | |
86 { | |
87 messages = results[1]; | |
88 } | |
89 showLogin(); | |
90 } | |
91 } | |
92 | |
93 // resetLogin method: if logged in, 'logs out' and allows a different user/pass to be entered | |
94 function resetLogin() | |
95 { | |
96 loggedIn = false; | |
97 hasSeed = false; | |
98 } |