includes/clientside/static/login.js
changeset 688 f2a824ce5f18
parent 651 ce9d78d7251d
child 694 43367c66d869
equal deleted inserted replaced
687:ea43ac1ff2ee 688:f2a824ce5f18
   522   }
   522   }
   523   
   523   
   524   // Done building the main part of the form
   524   // Done building the main part of the form
   525   form.appendChild(table);
   525   form.appendChild(table);
   526   
   526   
       
   527   // Field: remember login
       
   528   if ( logindata.user_level <= USER_LEVEL_MEMBER )
       
   529   {
       
   530     var lbl_remember = document.createElement('label');
       
   531     lbl_remember.style.fontSize = 'smaller';
       
   532     lbl_remember.style.display = 'block';
       
   533     lbl_remember.style.textAlign = 'center';
       
   534     
       
   535     // figure out what text to put in the "remember me" checkbox
       
   536     // infinite session length?
       
   537     if ( data.extended_time == 0 )
       
   538     {
       
   539       // yes, infinite
       
   540       var txt_remember = $lang.get('user_login_ajax_check_remember_infinite');
       
   541     }
       
   542     else
       
   543     {
       
   544       if ( data.extended_time % 7 == 0 )
       
   545       {
       
   546         // number of days is a multiple of 7
       
   547         // use weeks as our unit
       
   548         var sess_time = data.extended_time / 7;
       
   549         var unit = 'week';
       
   550       }
       
   551       else
       
   552       {
       
   553         // use days as our unit
       
   554         var sess_time = data.extended_time;
       
   555         var unit = 'day';
       
   556       }
       
   557       // more than one week or day?
       
   558       if ( sess_time != 1 )
       
   559         unit += 's';
       
   560       
       
   561       // assemble the string
       
   562       var txt_remember = $lang.get('user_login_ajax_check_remember', {
       
   563           session_length: sess_time,
       
   564           length_units: $lang.get('etc_unit_' + unit)
       
   565         });
       
   566     }
       
   567     var check_remember = document.createElement('input');
       
   568     check_remember.type = 'checkbox';
       
   569     // this onclick attribute changes the cookie whenever the checkbox or label is clicked
       
   570     check_remember.setAttribute('onclick', 'var ck = ( this.checked ) ? "enable" : "disable"; createCookie("login_remember", ck, 3650);');
       
   571     if ( readCookie('login_remember') != 'disable' )
       
   572       check_remember.setAttribute('checked', 'checked');
       
   573     check_remember.id = 'ajax_login_field_remember';
       
   574     lbl_remember.appendChild(check_remember);
       
   575     lbl_remember.innerHTML += ' ' + txt_remember;
       
   576     
       
   577     form.appendChild(lbl_remember);
       
   578   }
       
   579   
   527   // Field: enable Diffie Hellman
   580   // Field: enable Diffie Hellman
   528   if ( IE || is_iPhone )
   581   if ( IE || is_iPhone )
   529   {
   582   {
   530     var lbl_dh = document.createElement('span');
   583     var lbl_dh = document.createElement('span');
   531     lbl_dh.style.fontSize = 'smaller';
   584     lbl_dh.style.fontSize = 'smaller';
   624     };
   677     };
   625     ajaxLoginShowFriendlyError(fake_packet);
   678     ajaxLoginShowFriendlyError(fake_packet);
   626   }
   679   }
   627 }
   680 }
   628 
   681 
   629 window.ajaxLoginSubmitForm = function(real, username, password, captcha)
   682 window.ajaxLoginSubmitForm = function(real, username, password, captcha, remember)
   630 {
   683 {
   631   // Perform AES test to make sure it's all working
   684   // Perform AES test to make sure it's all working
   632   if ( !aes_self_test() )
   685   if ( !aes_self_test() )
   633   {
   686   {
   634     alert('BUG: AES self-test failed');
   687     alert('BUG: AES self-test failed');
   646     setTimeout(function() {
   699     setTimeout(function() {
   647         var d = document.getElementById('autoCaptcha');
   700         var d = document.getElementById('autoCaptcha');
   648         d.parentNode.removeChild(d);
   701         d.parentNode.removeChild(d);
   649       }, to);
   702       }, to);
   650   }
   703   }
       
   704   // "Remember session" switch
       
   705   if ( typeof(remember) == 'boolean' )
       
   706   {
       
   707     var remember_session = remember;
       
   708   }
       
   709   else
       
   710   {
       
   711     if ( document.getElementById('ajax_login_field_remember') )
       
   712     {
       
   713       var remember_session = ( document.getElementById('ajax_login_field_remember').checked ) ? true : false;
       
   714     }
       
   715     else
       
   716     {
       
   717       var remember_session = false;
       
   718     }
       
   719   }
   651   // Encryption: preprocessor
   720   // Encryption: preprocessor
   652   if ( real )
   721   if ( real )
   653   {
   722   {
   654     var do_dh = true;
   723     var do_dh = true;
   655   }
   724   }
   693     if ( !real )
   762     if ( !real )
   694     {
   763     {
   695       // Wait while the browser updates the login window
   764       // Wait while the browser updates the login window
   696       setTimeout(function()
   765       setTimeout(function()
   697         {
   766         {
   698           ajaxLoginSubmitForm(true, username, password, captcha);
   767           ajaxLoginSubmitForm(true, username, password, captcha, remember_session);
   699         }, 200);
   768         }, 200);
   700       return true;
   769       return true;
   701     }
   770     }
   702     // Perform Diffie Hellman stuff
   771     // Perform Diffie Hellman stuff
   703     var dh_priv = dh_gen_private();
   772     var dh_priv = dh_gen_private();
   748       captcha_code: captcha_code,
   817       captcha_code: captcha_code,
   749       captcha_hash: captcha_hash,
   818       captcha_hash: captcha_hash,
   750       dh_public_key: logindata.key_dh,
   819       dh_public_key: logindata.key_dh,
   751       dh_client_key: dh_pub,
   820       dh_client_key: dh_pub,
   752       dh_secret_hash: secret_hash,
   821       dh_secret_hash: secret_hash,
   753       level: logindata.user_level
   822       level: logindata.user_level,
       
   823       remember: remember_session
   754     }
   824     }
   755   }
   825   }
   756   else
   826   else
   757   {
   827   {
   758     var json_packet = {
   828     var json_packet = {
   759       mode: 'login_aes',
   829       mode: 'login_aes',
   760       userinfo: userinfo,
   830       userinfo: userinfo,
   761       captcha_code: captcha_code,
   831       captcha_code: captcha_code,
   762       captcha_hash: captcha_hash,
   832       captcha_hash: captcha_hash,
   763       key_aes: hex_md5(crypt_key),
   833       key_aes: hex_md5(crypt_key),
   764       level: logindata.user_level
   834       level: logindata.user_level,
       
   835       remember: remember_session
   765     }
   836     }
   766   }
   837   }
   767   ajaxLoginPerformRequest(json_packet);
   838   ajaxLoginPerformRequest(json_packet);
   768 }
   839 }
   769 
   840