includes/clientside/static/login.js
changeset 460 3a1c99845ca8
parent 436 242353360e37
child 461 717e71109645
equal deleted inserted replaced
459:31c23016ab62 460:3a1c99845ca8
   325     new messagebox(MB_ICONSTOP | MB_OK, 'FIXME L10N: There was an error in the login process', 'The following error code came from the server:<br />' + response.error);
   325     new messagebox(MB_ICONSTOP | MB_OK, 'FIXME L10N: There was an error in the login process', 'The following error code came from the server:<br />' + response.error);
   326     return false;
   326     return false;
   327   }
   327   }
   328   // Rid ourselves of any loading windows
   328   // Rid ourselves of any loading windows
   329   ajaxLoginSetStatus(AJAX_STATUS_DESTROY);
   329   ajaxLoginSetStatus(AJAX_STATUS_DESTROY);
       
   330   if ( IE )
       
   331   {
       
   332     alert('Login: got AJAX response');
       
   333   }
   330   // Main mode switch
   334   // Main mode switch
   331   switch ( response.mode )
   335   switch ( response.mode )
   332   {
   336   {
   333     case 'build_box':
   337     case 'build_box':
   334       // The server wants us to build the login form, all the information is there
   338       // The server wants us to build the login form, all the information is there
   384   form.onsubmit = function()
   388   form.onsubmit = function()
   385   {
   389   {
   386     ajaxLoginSubmitForm();
   390     ajaxLoginSubmitForm();
   387     return false;
   391     return false;
   388   }
   392   }
       
   393   if ( IE )
       
   394   {
       
   395     form.style.marginTop = '-20px';
       
   396   }
   389   
   397   
   390   // Using tables to wrap form elements because it results in a
   398   // Using tables to wrap form elements because it results in a
   391   // more visually appealing form. Yes, tables suck. I don't really
   399   // more visually appealing form. Yes, tables suck. I don't really
   392   // care - they make forms look good.
   400   // care - they make forms look good.
   393   
   401   
   471   
   479   
   472   // Done building the main part of the form
   480   // Done building the main part of the form
   473   form.appendChild(table);
   481   form.appendChild(table);
   474   
   482   
   475   // Field: enable Diffie Hellman
   483   // Field: enable Diffie Hellman
   476   var lbl_dh = document.createElement('label');
   484   if ( IE )
   477   lbl_dh.style.fontSize = 'smaller';
   485   {
   478   lbl_dh.style.display = 'block';
   486     var lbl_dh = document.createElement('span');
   479   lbl_dh.style.textAlign = 'center';
   487     lbl_dh.style.fontSize = 'smaller';
   480   var check_dh = document.createElement('input');
   488     lbl_dh.style.display = 'block';
   481   check_dh.type = 'checkbox';
   489     lbl_dh.style.textAlign = 'center';
   482   // this onclick attribute changes the cookie whenever the checkbox or label is clicked
   490     lbl_dh.innerHTML = $lang.get('user_login_ajax_check_dh_ie');
   483   check_dh.setAttribute('onclick', 'var ck = ( this.checked ) ? "enable" : "disable"; createCookie("diffiehellman_login", ck, 3650);');
   491     form.appendChild(lbl_dh);
   484   if ( readCookie('diffiehellman_login') != 'disable' )
   492   }
   485     check_dh.setAttribute('checked', 'checked');
   493   else
   486   check_dh.id = 'ajax_login_field_dh';
   494   {
   487   lbl_dh.appendChild(check_dh);
   495     var lbl_dh = document.createElement('label');
   488   lbl_dh.innerHTML += $lang.get('user_login_ajax_check_dh');
   496     lbl_dh.style.fontSize = 'smaller';
   489   form.appendChild(lbl_dh);
   497     lbl_dh.style.display = 'block';
   490   
   498     lbl_dh.style.textAlign = 'center';
   491   div.appendChild(form);
   499     var check_dh = document.createElement('input');
       
   500     check_dh.type = 'checkbox';
       
   501     // this onclick attribute changes the cookie whenever the checkbox or label is clicked
       
   502     check_dh.setAttribute('onclick', 'var ck = ( this.checked ) ? "enable" : "disable"; createCookie("diffiehellman_login", ck, 3650);');
       
   503     if ( readCookie('diffiehellman_login') != 'disable' )
       
   504       check_dh.setAttribute('checked', 'checked');
       
   505     check_dh.id = 'ajax_login_field_dh';
       
   506     lbl_dh.appendChild(check_dh);
       
   507     lbl_dh.innerHTML += $lang.get('user_login_ajax_check_dh');
       
   508     form.appendChild(lbl_dh);
       
   509   }
       
   510   
       
   511   if ( IE )
       
   512   {
       
   513     div.innerHTML += form.outerHTML;
       
   514   }
       
   515   else
       
   516   {
       
   517     div.appendChild(form);
       
   518   }
   492   
   519   
   493   // Diagnostic / help links
   520   // Diagnostic / help links
   494   // (only displayed in login, not in re-auth)
   521   // (only displayed in login, not in re-auth)
   495   if ( logindata.user_level == USER_LEVEL_MEMBER )
   522   if ( logindata.user_level == USER_LEVEL_MEMBER )
   496   {
   523   {
   511   // Insert the entire form into the login window
   538   // Insert the entire form into the login window
   512   logindata.mb_inner.innerHTML = '';
   539   logindata.mb_inner.innerHTML = '';
   513   logindata.mb_inner.appendChild(div);
   540   logindata.mb_inner.appendChild(div);
   514   
   541   
   515   // Post operations: field focus
   542   // Post operations: field focus
   516   if ( data.username )
   543   if ( IE )
   517     f_password.focus();
   544   {
       
   545     setTimeout(
       
   546       function()
       
   547       {
       
   548         if ( logindata.loggedin_username )
       
   549           document.getElementById('ajax_login_field_password').focus();
       
   550         else
       
   551           document.getElementById('ajax_login_field_username').focus();
       
   552       }, 200);        
       
   553   }
   518   else
   554   else
   519     f_username.focus();
   555   {
       
   556     if ( data.username )
       
   557       f_password.focus();
       
   558     else
       
   559       f_username.focus();
       
   560   }
   520   
   561   
   521   // Post operations: show captcha window
   562   // Post operations: show captcha window
   522   if ( show_captcha )
   563   if ( show_captcha )
   523     ajaxShowCaptcha(show_captcha);
   564     ajaxShowCaptcha(show_captcha);
   524   
   565   
   525   // Post operations: stash encryption keys and All That Jazz(TM)
   566   // Post operations: stash encryption keys and All That Jazz(TM)
   526   logindata.key_aes = data.aes_key;
   567   logindata.key_aes = data.aes_key;
   527   logindata.key_dh = data.dh_public_key;
   568   logindata.key_dh = data.dh_public_key;
   528   logindata.captcha_hash = show_captcha;
   569   logindata.captcha_hash = show_captcha;
       
   570   logindata.loggedin_username = data.username
   529   
   571   
   530   // Are we locked out? If so simulate an error and disable the controls
   572   // Are we locked out? If so simulate an error and disable the controls
   531   if ( data.lockout_info.lockout_policy == 'lockout' && data.locked_out )
   573   if ( data.lockout_info.lockout_policy == 'lockout' && data.locked_out )
   532   {
   574   {
   533     f_username.setAttribute('disabled', 'disabled');
   575     f_username.setAttribute('disabled', 'disabled');
   571   {
   613   {
   572     var do_dh = document.getElementById('ajax_login_field_dh').checked;
   614     var do_dh = document.getElementById('ajax_login_field_dh').checked;
   573   }
   615   }
   574   else
   616   else
   575   {
   617   {
   576     // The user probably clicked ok when the form wasn't in there.
   618     if ( IE )
   577     return false;
   619     {
       
   620       // IE doesn't have this control, continue silently IF the rest
       
   621       // of the login form is there
       
   622       if ( !document.getElementById('ajax_login_field_username') )
       
   623       {
       
   624         return false;
       
   625       }
       
   626     }
       
   627     else
       
   628     {
       
   629       // The user probably clicked ok when the form wasn't in there.
       
   630       return false;
       
   631     }
   578   }
   632   }
   579   if ( !username )
   633   if ( !username )
   580   {
   634   {
   581     var username = document.getElementById('ajax_login_field_username').value;
   635     var username = document.getElementById('ajax_login_field_username').value;
   582   }
   636   }