includes/clientside/static/login.js
changeset 1001 79770fb4132a
parent 907 44851d7e9bda
child 1002 4d1bb8deee88
equal deleted inserted replaced
1000:dbefcae6b5cd 1001:79770fb4132a
   374 /**
   374 /**
   375  * Performs an AJAX logon request to the server and calls ajaxLoginProcessResponse() on the result.
   375  * Performs an AJAX logon request to the server and calls ajaxLoginProcessResponse() on the result.
   376  * @param object JSON packet to send
   376  * @param object JSON packet to send
   377  */
   377  */
   378 
   378 
   379 window.ajaxLoginPerformRequest = function(json)
   379 window.ajaxLoginPerformRequest = function(json, _hookfunc)
   380 {
   380 {
   381   json = toJSONString(json);
   381   json = toJSONString(json);
   382   json = ajaxEscape(json);
   382   json = ajaxEscape(json);
       
   383   var hookfunc = typeof(_hookfunc) == 'function' ? _hookfunc : false;
   383   ajaxPost(makeUrlNS('Special', 'Login/action.json'), 'r=' + json, function(ajax)
   384   ajaxPost(makeUrlNS('Special', 'Login/action.json'), 'r=' + json, function(ajax)
   384     {
   385     {
   385       if ( ajax.readyState == 4 && ajax.status == 200 )
   386       if ( ajax.readyState == 4 && ajax.status == 200 )
   386       {
   387       {
   387         // parse response
   388         // parse response
   390         {
   391         {
   391           handle_invalid_json(response);
   392           handle_invalid_json(response);
   392           return false;
   393           return false;
   393         }
   394         }
   394         response = parseJSON(response);
   395         response = parseJSON(response);
   395         ajaxLoginProcessResponse(response);
   396         ajaxLoginProcessResponse(response, hookfunc);
   396       }
   397       }
   397     }, true);
   398     }, true);
   398 }
   399 }
   399 
   400 
   400 /**
   401 /**
   401  * Processes a response from the login server
   402  * Processes a response from the login server
   402  * @param object JSON response
   403  * @param object JSON response
   403  */
   404  */
   404 
   405 
   405 window.ajaxLoginProcessResponse = function(response)
   406 window.ajaxLoginProcessResponse = function(response, hookfunc)
   406 {
   407 {
   407   // Did the server send a plaintext error?
   408   // Did the server send a plaintext error?
   408   if ( response.mode == 'error' )
   409   if ( response.mode == 'error' )
   409   {
   410   {
   410     if ( logindata.mb_object )
   411     if ( logindata.mb_object )
   428       // The server wants us to build the login form, all the information is there
   429       // The server wants us to build the login form, all the information is there
   429       ajaxLoginBuildForm(response);
   430       ajaxLoginBuildForm(response);
   430       break;
   431       break;
   431     case 'login_success':
   432     case 'login_success':
   432       ajaxLoginSetStatus(AJAX_STATUS_SUCCESS);
   433       ajaxLoginSetStatus(AJAX_STATUS_SUCCESS);
   433       logindata.successfunc(response.key);
   434       logindata.successfunc(response.key, response);
   434       break;
   435       break;
   435     case 'login_failure':
   436     case 'login_failure':
   436       // Rid ourselves of any loading windows
   437       // Rid ourselves of any loading windows
   437       ajaxLoginSetStatus(AJAX_STATUS_DESTROY);
   438       ajaxLoginSetStatus(AJAX_STATUS_DESTROY);
   438       document.getElementById('messageBox').style.backgroundColor = '#C0C0C0';
   439       document.getElementById('messageBox').style.backgroundColor = '#C0C0C0';
   473         ajaxLoginReplaceSIDInline(false, ENANO_SID, USER_LEVEL_MEMBER);
   474         ajaxLoginReplaceSIDInline(false, ENANO_SID, USER_LEVEL_MEMBER);
   474       }
   475       }
   475       break;
   476       break;
   476     case 'noop':
   477     case 'noop':
   477       break;
   478       break;
       
   479   }
       
   480   if ( hookfunc )
       
   481   {
       
   482     hookfunc(response);
   478   }
   483   }
   479 }
   484 }
   480 
   485 
   481 /*
   486 /*
   482  * RESPONSE HANDLERS
   487  * RESPONSE HANDLERS
  1123         color: 'blue',
  1128         color: 'blue',
  1124         onclick: function()
  1129         onclick: function()
  1125         {
  1130         {
  1126           var mp = miniPromptGetParent(this);
  1131           var mp = miniPromptGetParent(this);
  1127           var whitey = whiteOutMiniPrompt(mp);
  1132           var whitey = whiteOutMiniPrompt(mp);
  1128           setTimeout(function()
       
  1129             {
       
  1130               whiteOutReportSuccess(whitey);
       
  1131               setTimeout(function()
       
  1132                 {
       
  1133                   miniPromptDestroy(mp);
       
  1134                 }, 1250);
       
  1135             }, 1000);
       
  1136           
  1133           
  1137           ajaxLoginPerformRequest({
  1134           ajaxLoginPerformRequest({
  1138               mode:  'logout',
  1135               mode:  'logout',
  1139               level: auth_level,
  1136               level: auth_level,
  1140               csrf_token: csrf_token
  1137               csrf_token: csrf_token
  1141           });
  1138           }, function(response)
       
  1139             {
       
  1140               whiteOutReportSuccess(whitey);
       
  1141                 setTimeout(function()
       
  1142                   {
       
  1143                     miniPromptDestroy(mp);
       
  1144                   }, 1250);
       
  1145             });
  1142           return false;
  1146           return false;
  1143         }
  1147         }
  1144       });
  1148       });
  1145   }
  1149   }
  1146   buttons.push({
  1150   buttons.push({
  1260   window.location = loc;
  1264   window.location = loc;
  1261 }
  1265 }
  1262 
  1266 
  1263 window.ajaxDynamicReauth = function(adminpage, level)
  1267 window.ajaxDynamicReauth = function(adminpage, level)
  1264 {
  1268 {
       
  1269   if ( auth_level < USER_LEVEL_ADMIN )
       
  1270   {
       
  1271     ajaxStartLogin();
       
  1272     return false;
       
  1273   }
       
  1274   
  1265   var old_sid = ENANO_SID;
  1275   var old_sid = ENANO_SID;
  1266   var targetpage = adminpage;
  1276   var targetpage = adminpage;
  1267   if ( !level )
  1277   if ( !level )
  1268   {
  1278   {
  1269     level = USER_LEVEL_ADMIN;
  1279     level = USER_LEVEL_ADMIN;
  1270   }
  1280   }
  1271   ajaxLogonInit(function(k)
  1281   ajaxLogonInit(function(k, response)
  1272     {
  1282     {
  1273       ajaxLoginReplaceSIDInline(k, old_sid, level);
  1283       ajaxLoginReplaceSIDInline(k, old_sid, level);
       
  1284       window.user_id = response.user_id;
       
  1285       window.user_level = response.user_level;
  1274       mb_current_obj.destroy();
  1286       mb_current_obj.destroy();
  1275       console.debug(targetpage);
       
  1276       if ( typeof(targetpage) == 'string' )
  1287       if ( typeof(targetpage) == 'string' )
  1277       {
  1288       {
  1278         ajaxPage(targetpage);
  1289         ajaxPage(targetpage);
  1279       }
  1290       }
  1280       else if ( typeof(targetpage) == 'function' )
  1291       else if ( typeof(targetpage) == 'function' )