298 if ( typeof(call_on_ok) == 'function' ) |
298 if ( typeof(call_on_ok) == 'function' ) |
299 { |
299 { |
300 ajax_auth_prompt_cache = call_on_ok; |
300 ajax_auth_prompt_cache = call_on_ok; |
301 } |
301 } |
302 if ( !level ) |
302 if ( !level ) |
303 level = 2; |
303 level = USER_LEVEL_MEMBER; |
304 ajax_auth_level_cache = level; |
304 ajax_auth_level_cache = level; |
305 var loading_win = '<div align="center" style="text-align: center;"> \ |
305 var loading_win = '<div align="center" style="text-align: center;"> \ |
306 <p>Fetching an encryption key...</p> \ |
306 <p>Fetching an encryption key...</p> \ |
307 <p><small>Not working? Use the <a href="'+makeUrlNS('Special', 'Login/' + title)+'">alternate login form</a>.</p> \ |
307 <p><small>Not working? Use the <a href="'+makeUrlNS('Special', 'Login/' + title)+'">alternate login form</a>.</p> \ |
308 <p><img alt="Please wait..." src="'+scriptPath+'/images/loading-big.gif" /></p> \ |
308 <p><img alt="Please wait..." src="'+scriptPath+'/images/loading-big.gif" /></p> \ |
309 </div>'; |
309 </div>'; |
310 ajax_auth_mb_cache = new messagebox(MB_OKCANCEL|MB_ICONLOCK, 'Please enter your username and password to continue.', loading_win); |
310 var title = ( level > USER_LEVEL_MEMBER ) ? 'You are requesting a sensitive operation.' : 'Please enter your username and password to continue.'; |
|
311 ajax_auth_mb_cache = new messagebox(MB_OKCANCEL|MB_ICONLOCK, title, loading_win); |
311 ajax_auth_mb_cache.onbeforeclick['OK'] = ajaxValidateLogin; |
312 ajax_auth_mb_cache.onbeforeclick['OK'] = ajaxValidateLogin; |
312 ajaxAuthLoginInnerSetup(); |
313 ajaxAuthLoginInnerSetup(); |
313 } |
314 } |
314 |
315 |
315 function ajaxAuthLoginInnerSetup() |
316 function ajaxAuthLoginInnerSetup() |
322 { |
323 { |
323 alert('Invalid JSON response from server: ' + response); |
324 alert('Invalid JSON response from server: ' + response); |
324 return false; |
325 return false; |
325 } |
326 } |
326 response = parseJSON(response); |
327 response = parseJSON(response); |
327 var form_html = ' \ |
328 var level = ajax_auth_level_cache; |
|
329 var form_html = ''; |
|
330 if ( level > USER_LEVEL_MEMBER ) |
|
331 { |
|
332 form_html += 'Please re-enter your login details, to verify your identity.<br /><br />'; |
|
333 } |
|
334 form_html += ' \ |
328 <table border="0" align="center"> \ |
335 <table border="0" align="center"> \ |
329 <tr> \ |
336 <tr> \ |
330 <td>Username:</td><td><input tabindex="1" id="ajaxlogin_user" type="text" size="25" /> \ |
337 <td>Username:</td><td><input tabindex="1" id="ajaxlogin_user" type="text" size="25" /> \ |
331 </tr> \ |
338 </tr> \ |
332 <tr> \ |
339 <tr> \ |
333 <td>Password:</td><td><input tabindex="2" id="ajaxlogin_pass" type="password" size="25" /> \ |
340 <td>Password:</td><td><input tabindex="2" id="ajaxlogin_pass" type="password" size="25" /> \ |
334 </tr> \ |
341 </tr> \ |
335 <tr> \ |
342 <tr> \ |
336 <td colspan="2" style="text-align: center;"> \ |
343 <td colspan="2" style="text-align: center;"> \ |
337 <br /><small>Trouble logging in? Try the <a href="'+makeUrlNS('Special', 'Login/' + title)+'">full login form</a>.<br /> \ |
344 <br /><small>Trouble logging in? Try the <a href="'+makeUrlNS('Special', 'Login/' + title)+'">full login form</a>.<br />'; |
|
345 if ( level <= USER_LEVEL_MEMBER ) |
|
346 { |
|
347 form_html += ' \ |
338 Did you <a href="'+makeUrlNS('Special', 'PasswordReset')+'">forget your password</a>?<br /> \ |
348 Did you <a href="'+makeUrlNS('Special', 'PasswordReset')+'">forget your password</a>?<br /> \ |
339 Maybe you need to <a href="'+makeUrlNS('Special', 'Register')+'">create an account</a>.</small> \ |
349 Maybe you need to <a href="'+makeUrlNS('Special', 'Register')+'">create an account</a>.</small>'; |
|
350 } |
|
351 form_html += ' \ |
340 </td> \ |
352 </td> \ |
341 </tr> \ |
353 </tr> \ |
342 </table> \ |
354 </table> \ |
343 <input type="hidden" id="ajaxlogin_crypt_key" value="' + response.key + '" /> \ |
355 <input type="hidden" id="ajaxlogin_crypt_key" value="' + response.key + '" /> \ |
344 <input type="hidden" id="ajaxlogin_crypt_challenge" value="' + response.challenge + '" /> \ |
356 <input type="hidden" id="ajaxlogin_crypt_challenge" value="' + response.challenge + '" /> \ |
345 </form>'; |
357 </form>'; |
346 ajax_auth_mb_cache.updateContent(form_html); |
358 ajax_auth_mb_cache.updateContent(form_html); |
347 $('messageBox').object.nextSibling.firstChild.tabindex = '3'; |
359 $('messageBox').object.nextSibling.firstChild.tabindex = '3'; |
348 $('ajaxlogin_user').object.focus(); |
360 if ( typeof(response.username) == 'string' ) |
|
361 { |
|
362 $('ajaxlogin_user').object.value = response.username; |
|
363 $('ajaxlogin_pass').object.focus(); |
|
364 } |
|
365 else |
|
366 { |
|
367 $('ajaxlogin_user').object.focus(); |
|
368 } |
349 $('ajaxlogin_pass').object.onblur = function(e) { if ( !shift ) $('messageBox').object.nextSibling.firstChild.focus(); }; |
369 $('ajaxlogin_pass').object.onblur = function(e) { if ( !shift ) $('messageBox').object.nextSibling.firstChild.focus(); }; |
350 $('ajaxlogin_pass').object.onkeypress = function(e) { if ( !e && IE ) return true; if ( e.keyCode == 13 ) $('messageBox').object.nextSibling.firstChild.click(); }; |
370 $('ajaxlogin_pass').object.onkeypress = function(e) { if ( !e && IE ) return true; if ( e.keyCode == 13 ) $('messageBox').object.nextSibling.firstChild.click(); }; |
351 } |
371 } |
352 }); |
372 }); |
353 } |
373 } |