jQuery login issue
<p>I have a link with two classes:</p>

<pre><code>&lt;a href="#" class="loginable postStory"&gt;Share Your Quirks&lt;/a&gt;
</code></pre>

<p>loginable checks if user is logged in and, if not, presents a "modal" login popup:</p>

<pre><code>$(".loginable").live("click",function(e) {                        
    $.getJSON("/cfcs/global.cfc?method=userAuthenticated&amp;returnformat=json", {}, function(res,code) {
        if(res == 0){
            doSiteLogin();
        }
    });
})
</code></pre>

<p>postStory loads a form for adding a story:</p>

<pre><code>$(".postStory").live("click", function(e) {
    $(function() {
        $("#divCentre").load(siteRoot + "add_story.cfm?mode=create");
    })
});
</code></pre>

<p>The idea is that once the link is clicked, we don't want to show the add_story page unless the user is logged in, i.e. we need to user to stay on the current page UNTIL they've successfully logged in. But currently, it displays the add_story page AND the login popup. </p>

<p>To see what I mean, go to www.quirkup.com and click the "Share your quirks" link at the top of the "True Confessions" section.</p>

<p>The problem is that the user can close the modal window without logging in and can start filling in the form. I realise I can probably hide the form until the login is completed, but I'm wondering if there's a better way.</p>

<h2>Edit</h2>

<p>THe doSiteLogin() function looks like this</p>

<pre><code>function doSiteLogin() {
        ColdFusion.Window.create('loginwindow','Login','/inc_site_login_form.cfm',{x:400,y:300,height:200,width:300,center:true,modal:true});
    }

    function handleSiteLogin() {
        ColdFusion.Ajax.submitForm('siteloginform','/processLogin.cfm',handleSiteLoginResponse);
    }

    function handleSiteLoginResponse(s) { 
        var userid = s.split("^")[0] || 0;
        var firstname = s.split("^")[1] || 0;
        var lastname = s.split("^")[2] || 0;
        var usertype = s.split("^")[3] || 0;
        var confirmed = s.split("^")[4] || 0;
        var enabled = s.split("^")[5] || 0;
        var authenticated = s.split("^")[6] || 0;

        if(authenticated == 1){
            ColdFusion.Window.hide('loginwindow');
            alert('Successfully logged in.\nRefreshing page...');
            window.location.reload();
        }else{
            if(confirmed != 1){
                alert('Your account has not been activated. Please ensure you have clicked the confirmation link in your email.');
                return false;
            }else if(!enabled || enabled.toLowerCase() == 'no'){
                alert('Your account is not activated. Please contact Quirkup.');
                return false;
            }else{
                alert('Your login failed. Please try again.\nIf the problem persists, or you have forgotten your login details, please email info@asia-buy.com.');
                return false;
            }
        }
    }
</code></pre>
