309 var $errstring = $data.error; |
309 var $errstring = $data.error; |
310 // this was literally copied straight from the PHP code. |
310 // this was literally copied straight from the PHP code. |
311 switch($data.error) |
311 switch($data.error) |
312 { |
312 { |
313 case 'key_not_found': |
313 case 'key_not_found': |
314 $errstring = 'Enano couldn\'t look up the encryption key used to encrypt your password. This most often happens if a cache rotation occurred during your login attempt, or if you refreshed the login page.'; |
314 $errstring = $lang.get('user_err_key_not_found'); |
315 break; |
315 break; |
316 case 'key_wrong_length': |
316 case 'key_wrong_length': |
317 $errstring = 'The encryption key was the wrong length.'; |
317 $errstring = $lang.get('user_err_key_wrong_length'); |
318 break; |
318 break; |
319 case 'too_big_for_britches': |
319 case 'too_big_for_britches': |
320 $errstring = 'You are trying to authenticate at a level that your user account does not permit.'; |
320 $errstring = $lang.get('user_err_too_big_for_britches'); |
321 break; |
321 break; |
322 case 'invalid_credentials': |
322 case 'invalid_credentials': |
323 $errstring = 'You have entered an invalid username or password. Please enter your login details again.'; |
323 $errstring = $lang.get('user_err_invalid_credentials'); |
|
324 var subst = { |
|
325 lockout_fails: $data.lockout_fails, |
|
326 lockout_threshold: $data.lockout_threshold, |
|
327 lockout_duration: $data.lockout_duration |
|
328 } |
324 if ( $data.lockout_policy == 'lockout' ) |
329 if ( $data.lockout_policy == 'lockout' ) |
325 { |
330 { |
326 $errstring += ' You have used up '+$data['lockout_fails']+' out of '+$data['lockout_threshold']+' login attempts. After you have used up all '+$data['lockout_threshold']+' login attempts, you will be locked out from logging in for '+$data['lockout_duration']+' minutes.'; |
331 $errstring += $lang.get('user_err_invalid_credentials_lockout', subst); |
327 } |
332 } |
328 else if ( $data.lockout_policy == 'captcha' ) |
333 else if ( $data.lockout_policy == 'captcha' ) |
329 { |
334 { |
330 $errstring += ' You have used up '+$data['lockout_fails']+' out of '+$data['lockout_threshold']+' login attempts. After you have used up all '+$data['lockout_threshold']+' login attempts, you will have to enter a visual confirmation code before logging in, effective for '+$data['lockout_duration']+' minutes.'; |
335 $errstring += $lang.get('user_err_invalid_credentials_lockout_captcha', subst); |
331 } |
336 } |
332 break; |
337 break; |
333 case 'backend_fail': |
338 case 'backend_fail': |
334 $errstring = 'You entered the right credentials and everything was validated, but for some reason Enano couldn\'t register your session. This is an internal problem with the site and you are encouraged to contact site administration.'; |
339 $errstring = $lang.get('user_err_backend_fail'); |
335 break; |
340 break; |
336 case 'locked_out': |
341 case 'locked_out': |
337 $attempts = parseInt($data['lockout_fails']); |
342 $attempts = parseInt($data['lockout_fails']); |
338 if ( $attempts > $data['lockout_threshold']) |
343 if ( $attempts > $data['lockout_threshold']) |
339 $attempts = $data['lockout_threshold']; |
344 $attempts = $data['lockout_threshold']; |
340 $time_rem = $data.time_rem; |
345 $time_rem = $data.time_rem; |
341 $s = ( $time_rem == 1 ) ? '' : 's'; |
346 $s = ( $time_rem == 1 ) ? '' : $lang.get('meta_plural'); |
342 $errstring = "You have used up all "+$data['lockout_threshold']+" allowed login attempts. Please wait "+$time_rem+" minute"+$s+" before attempting to log in again"; |
347 |
343 if ( $data['lockout_policy'] == 'captcha' ) |
348 var subst = { |
344 $errstring += ', or enter the visual confirmation code shown above in the appropriate box'; |
349 lockout_threshold: $data.lockout_threshold, |
345 $errstring += '.'; |
350 time_rem: $time_rem, |
|
351 plural: $s, |
|
352 captcha_blurb: ( $data.lockout_policy == 'captcha' ? $lang.get('user_err_locked_out_captcha_blurb') : '' ) |
|
353 } |
|
354 |
|
355 $errstring = $lang.get('user_err_locked_out', subst); |
|
356 |
346 break; |
357 break; |
347 } |
358 } |
348 return $errstring; |
359 return $errstring; |
349 } |
360 } |
350 |
361 |
356 } |
367 } |
357 if ( !level ) |
368 if ( !level ) |
358 level = USER_LEVEL_MEMBER; |
369 level = USER_LEVEL_MEMBER; |
359 ajax_auth_level_cache = level; |
370 ajax_auth_level_cache = level; |
360 var loading_win = '<div align="center" style="text-align: center;"> \ |
371 var loading_win = '<div align="center" style="text-align: center;"> \ |
361 <p>Fetching an encryption key...</p> \ |
372 <p>' + $lang.get('user_login_ajax_fetching_key') + '</p> \ |
362 <p><small>Not working? Use the <a href="'+makeUrlNS('Special', 'Login/' + title)+'">alternate login form</a>.</p> \ |
373 <p><small>' + $lang.get('user_login_ajax_link_fullform', { link_full_form: makeUrlNS('Special', 'Login/' + title) }) + '</p> \ |
363 <p><img alt="Please wait..." src="'+scriptPath+'/images/loading-big.gif" /></p> \ |
374 <p><img alt="Please wait..." src="'+scriptPath+'/images/loading-big.gif" /></p> \ |
364 </div>'; |
375 </div>'; |
365 var title = ( level > USER_LEVEL_MEMBER ) ? 'You are requesting a sensitive operation.' : 'Please enter your username and password to continue.'; |
376 var title = ( level > USER_LEVEL_MEMBER ) ? $lang.get('user_login_ajax_prompt_title_elev') : $lang.get('user_login_ajax_prompt_title'); |
366 ajax_auth_mb_cache = new messagebox(MB_OKCANCEL|MB_ICONLOCK, title, loading_win); |
377 ajax_auth_mb_cache = new messagebox(MB_OKCANCEL|MB_ICONLOCK, title, loading_win); |
367 ajax_auth_mb_cache.onbeforeclick['OK'] = ajaxValidateLogin; |
378 ajax_auth_mb_cache.onbeforeclick['OK'] = ajaxValidateLogin; |
368 ajax_auth_mb_cache.onbeforeclick['Cancel'] = function() |
379 ajax_auth_mb_cache.onbeforeclick['Cancel'] = function() |
369 { |
380 { |
370 if ( document.getElementById('autoCaptcha') ) |
381 if ( document.getElementById('autoCaptcha') ) |
414 form_html += '<div class="error-box-mini" id="ajax_auth_error">' + ajax_auth_error_string + '</div>'; |
425 form_html += '<div class="error-box-mini" id="ajax_auth_error">' + ajax_auth_error_string + '</div>'; |
415 ajax_auth_error_string = false; |
426 ajax_auth_error_string = false; |
416 } |
427 } |
417 else if ( level > USER_LEVEL_MEMBER ) |
428 else if ( level > USER_LEVEL_MEMBER ) |
418 { |
429 { |
419 form_html += 'Please re-enter your login details, to verify your identity.<br /><br />'; |
430 form_html += $lang.get('user_login_ajax_prompt_body_elev') + '<br /><br />'; |
420 } |
431 } |
421 if ( ajax_auth_show_captcha ) |
432 if ( ajax_auth_show_captcha ) |
422 { |
433 { |
423 var captcha_html = ' \ |
434 var captcha_html = ' \ |
424 <tr> \ |
435 <tr> \ |
425 <td>Code in image:</td> \ |
436 <td>' + $lang.get('user_login_field_captcha') + ':</td> \ |
426 <td><input type="hidden" id="ajaxlogin_captcha_hash" value="' + ajax_auth_show_captcha + '" /><input type="text" tabindex="3" size="25" id="ajaxlogin_captcha_code" /> \ |
437 <td><input type="hidden" id="ajaxlogin_captcha_hash" value="' + ajax_auth_show_captcha + '" /><input type="text" tabindex="3" size="25" id="ajaxlogin_captcha_code" /> \ |
427 </tr>'; |
438 </tr>'; |
428 } |
439 } |
429 else |
440 else |
430 { |
441 { |
432 } |
443 } |
433 var disableme = ( disable_controls ) ? 'disabled="disabled" ' : ''; |
444 var disableme = ( disable_controls ) ? 'disabled="disabled" ' : ''; |
434 form_html += ' \ |
445 form_html += ' \ |
435 <table border="0" align="center"> \ |
446 <table border="0" align="center"> \ |
436 <tr> \ |
447 <tr> \ |
437 <td>Username:</td><td><input tabindex="1" id="ajaxlogin_user" type="text" ' + disableme + 'size="25" /> \ |
448 <td>' + $lang.get('user_login_field_username') + ':</td><td><input tabindex="1" id="ajaxlogin_user" type="text" ' + disableme + 'size="25" /> \ |
438 </tr> \ |
449 </tr> \ |
439 <tr> \ |
450 <tr> \ |
440 <td>Password:</td><td><input tabindex="2" id="ajaxlogin_pass" type="password" ' + disableme + 'size="25" /> \ |
451 <td>' + $lang.get('user_login_field_password') + ':</td><td><input tabindex="2" id="ajaxlogin_pass" type="password" ' + disableme + 'size="25" /> \ |
441 </tr> \ |
452 </tr> \ |
442 ' + captcha_html + ' \ |
453 ' + captcha_html + ' \ |
443 <tr> \ |
454 <tr> \ |
444 <td colspan="2" style="text-align: center;"> \ |
455 <td colspan="2" style="text-align: center;"> \ |
445 <br /><small>Trouble logging in? Try the <a href="'+makeUrlNS('Special', 'Login/' + title, 'level=' + level)+'">full login form</a>.<br />'; |
456 <small>' + $lang.get('user_login_ajax_link_fullform', { link_full_form: makeUrlNS('Special', 'Login/' + title, 'level=' + level) }) + '<br />'; |
446 if ( level <= USER_LEVEL_MEMBER ) |
457 if ( level <= USER_LEVEL_MEMBER ) |
447 { |
458 { |
448 form_html += ' \ |
459 form_html += ' \ |
449 Did you <a href="'+makeUrlNS('Special', 'PasswordReset')+'">forget your password</a>?<br /> \ |
460 ' + $lang.get('user_login_ajax_link_forgotpass', { forgotpass_link: makeUrlNS('Special', 'PasswordReset') }) + '<br /> \ |
450 Maybe you need to <a href="'+makeUrlNS('Special', 'Register')+'">create an account</a>.</small>'; |
461 ' + $lang.get('user_login_createaccount_blurb', { reg_link: makeUrlNS('Special', 'Register') }); |
451 } |
462 } |
452 form_html += ' \ |
463 form_html += '</small> \ |
453 </td> \ |
464 </td> \ |
454 </tr> \ |
465 </tr> \ |
455 </table> \ |
466 </table> \ |
456 <input type="hidden" id="ajaxlogin_crypt_key" value="' + response.key + '" /> \ |
467 <input type="hidden" id="ajaxlogin_crypt_key" value="' + response.key + '" /> \ |
457 <input type="hidden" id="ajaxlogin_crypt_challenge" value="' + response.challenge + '" /> \ |
468 <input type="hidden" id="ajaxlogin_crypt_challenge" value="' + response.challenge + '" /> \ |
586 |
597 |
587 json_data = toJSONString(json_data); |
598 json_data = toJSONString(json_data); |
588 json_data = encodeURIComponent(json_data); |
599 json_data = encodeURIComponent(json_data); |
589 |
600 |
590 var loading_win = '<div align="center" style="text-align: center;"> \ |
601 var loading_win = '<div align="center" style="text-align: center;"> \ |
591 <p>Logging in...</p> \ |
602 <p>' + $lang.get('user_login_ajax_loggingin') + '</p> \ |
592 <p><img alt="Please wait..." src="'+scriptPath+'/images/loading-big.gif" /></p> \ |
603 <p><img alt="Please wait..." src="'+scriptPath+'/images/loading-big.gif" /></p> \ |
593 </div>'; |
604 </div>'; |
594 |
605 |
595 ajax_auth_mb_cache.updateContent(loading_win); |
606 ajax_auth_mb_cache.updateContent(loading_win); |
596 |
607 |