Mercurial > rlmcintyre
view 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 |
line wrap: on
line source
1 // js handling the login procedures3 // constants4 var NORMAL_STATE = 4;5 var LOGIN_PREFIX = 'login.php?';7 // variables8 var http = getHTTPObject(); // We create the HTTP Object9 var hasSeed = false;10 var loggedIn = false;11 var seed_id = 0;12 var seed = 0;13 var fullname = '';14 var messages = '';16 // getSeed method: gets a seed from the server for this transaction17 function getSeed()18 { // only get a seed if we're not logged in and we don't already have one19 if (!loggedIn && !hasSeed) {20 // open up the path21 http.open('GET', LOGIN_PREFIX + 'task=getseed', true);22 http.onreadystatechange = handleHttpGetSeed;23 http.send(null);24 }25 }27 // handleHttpGetSeed method: called when the seed is returned from the server28 function handleHttpGetSeed()29 {30 // if there hasn't been any errors31 if (http.readyState == NORMAL_STATE) {32 // split by the divider |33 results = http.responseText.split('|');35 // id is the first element36 seed_id = results[0];38 // seed is the second element39 seed = results[1];41 // now we have the seed42 hasSeed = true;43 }44 }46 // validateLogin method: validates a login request47 function validateLogin()48 {49 // ignore request if we are already logged in50 if (loggedIn)51 return;53 // get form form elements 'username' and 'password'54 username = document.getElementById('username').value;55 password = document.getElementById('password').value;57 // ignore if either is empty58 if (username != '' && password != '') {59 // compute the hash of the hash of the password and the seed60 hash = hex_md5(hex_md5(password) + seed);62 // open the http connection63 http.open('GET', LOGIN_PREFIX + 'task=checklogin&username='+username+'&id='+seed_id+'&hash='+hash, true);65 // where to go66 http.onreadystatechange = handleHttpValidateLogin;67 http.send(null);68 }69 }71 // handleHttpValidateLogin method: called when the validation results are returned from the server72 function handleHttpValidateLogin()73 {74 // did the connection work?75 if (http.readyState == NORMAL_STATE) {76 // split by the pipe77 results = http.responseText.split('|');78 if (results[0] == 'true')79 {80 hasSeed = false;81 loggedIn = true;82 fullname = results[1];83 messages = '';84 }85 else86 {87 messages = results[1];88 }89 showLogin();90 }91 }93 // resetLogin method: if logged in, 'logs out' and allows a different user/pass to be entered94 function resetLogin()95 {96 loggedIn = false;97 hasSeed = false;98 }