//File: user.js var bn_user = { favourites: new Array(), user: null, nickname: null, recently_viewed: {length: 0}, avatar: 'nobody', public_profile: 0, //do_after_login: null, //arguments_after_login: null, //Overridable functions for what to do on each page after login or slay after_login: function() {}, after_slay: function() {}, after_logout: function() {}, /** * Destroy the session then slay the user */ logout: function() { // Reason for the next bit of code: //We need to make sure that no matter what all privledges are taken away //that is why we use the slay. Inside the slay is a call to an overridable //function called after_slay, and here is a call to after_logout which is //also overridable. This means that each page can set what these actions //do. We need to do both after_slay and after_logout because the page should //never be redirected until the stax logout has completed because if the //next page loads and the user is still logged in(the stax call has not yet //completed) the user will appear to be logged in on the next page but then //the stax will complete destroying the session. Bad. //The solution is to continue with the slay no matter what, but only logout //after the stax call is finished. HENCE: IF YOUR LOGOUT ON A PAGE REQUIRES //A REDIRECT TO A NEW PAGE, YOU MUST ___MUST___ USE AFTER LOGOUT!! THIS IS //YOUR WARNING. IF YOU HAVE SIMILAR ISSUES, YOU DID NOT READ THIS FIRST OR //DID NOT PROPERLY HEED MY WARNING TO REMEMBER THIS WARNING! _logout(function(ret){ bn_user.after_logout(); data = JSON.parse(ret); if (data.success) { } }); bn_user.slay(); }, /** * Takes away user priveleges in javascript * @return void */ slay: function(){ bn_user.user = null; bn_user.nickname = null; bn_user.recently_viewed = {}; bn_user.avatar = 'nobody'; bn_user.public_profile = 0; bn_user.generate_greeting(); this.favourites = ''; return bn_user.after_slay(); }, /** * Checks if a user is logged in and logs the user in * @param recall boolean: recall the calling function on successful login * @return boolean */ check_login: function(recall, cb) { if (this.user == null) { if (recall) { do_after_login = arguments.callee.caller; arguments_after_login = arguments.callee.caller.arguments; } else { $("#LOGIN_ERROR").empty(); } $('#LOGIN_FORM').submit(function(){ $("#LOGIN_ERROR").empty(); if ($('#LOGIN_USERNAME').val() == '' || $('#LOGIN_PASSWORD').val() == '') { $("#LOGIN_ERROR").html('You must enter a username and a password.
'); $("#LOGIN_ERROR").show(); return false; } _do_login($('#LOGIN_USERNAME').val(), $('#LOGIN_PASSWORD').val(), $('#LOGIN_REMEMBER').attr('checked'), function(ret){ data = JSON.parse(ret); if (data.success) { $("#LOGIN_WINDOW").jqmHide(); bn_user.user = data.user; bn_user.nickname = data.nickname; bn_user.public_profile = data.public; bn_user.avatar = data.avatar; //Build the top link area //$('#GREETING').empty(); //$('#GREETING').append('Welcome, ' + bn_user.nickname + '. Sign Out'); //$('#MY_SAVED_NAMES_TOPLINK').show(); bn_user.favourites = data.favourites; if (typeof(do_after_login) != 'undefined' && do_after_login != null) { do_after_login.apply(this, arguments_after_login); do_after_login = null; } bn_user.recently_viewed = data.recent; bn_user.generate_greeting(); bn_user.after_login(); if($('input#LOGIN_REMEMBER').attr('checked')) { $.cookie('REMEMBER_USER', $('#LOGIN_USERNAME').val(), {expires: 365}); } } else { if (data.auth_code == 'LOCKED') { $("#LOGIN_ERROR").html('Your account has been lock please try again in 20 minutes.
'); } else { $("#LOGIN_ERROR").html('Could not log you in. Please check your credentials.
'); } $("#LOGIN_ERROR").show(); } }); return false; }); //cookie for remembering user login id if($.cookie('REMEMBER_USER')) $('#LOGIN_USERNAME').val($.cookie('REMEMBER_USER')); else $('#LOGIN_USERNAME').val(''); $('#LOGIN_PASSWORD').val(''); $('#LOGIN_WINDOW').jqmShow(); if($.cookie('REMEMBER_USER')) { $('input#LOGIN_REMEMBER').attr('checked', true); if($('#LOGIN_PASSWORD').val() != '') $('input#LOGIN_SUBMIT').focus(); else $('input#LOGIN_PASSWORD').focus(); } return false; } else { return true; } }, /** * Generates the top link area for logout/login and recently viewed */ generate_greeting: function() { $('#GREETING').empty(); $('#RECENT').empty(); $('#RECENT').append('

Recently Viewed

'); if (bn_user.recently_viewed.length) { $('#RECENT').append('