Show
Ignore:
Timestamp:
05/19/08 19:10:48 (19 months ago)
Author:
bchoate
Message:

Better handling for case where blog cookie and app session are out of sync. BugId:79508

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-38/default_templates/javascript.mtml

    r2377 r2393  
    130130<mt:Ignore> 
    131131/*** 
     132 * Called when an input field on the comment form receives focus. 
     133 */ 
     134</mt:Ignore> 
     135function mtCommentFormOnFocus() { 
     136    // if CAPTCHA is enabled, this causes the captcha image to be 
     137    // displayed if it hasn't been already. 
     138    mtShowCaptcha(); 
     139} 
     140 
     141<mt:Ignore> 
     142/*** 
    132143 * Displays a captcha field for anonymous commenters. 
    133144 */ 
     
    218229    if (u.profile) str += "profile:'" + mtEscapeJS(u.profile) + "';"; 
    219230    if (u.userpic) str += "userpic:'" + mtEscapeJS(u.userpic) + "';"; 
     231    if (u.sid) str += "sid:'" + mtEscapeJS(u.sid) + "';"; 
    220232    str += "is_trusted:'" + (u.is_trusted ? "1" : "0") + "';"; 
    221233    str += "is_author:'" + (u.is_author ? "1" : "0") + "';"; 
     
    238250    var u = {}; 
    239251    var m; 
    240     while (m = s.match(/^((name|url|email|is_authenticated|profile|userpic|is_trusted|is_author|is_banned|can_post|can_comment):'([^']+?)';?)/)) { 
     252    while (m = s.match(/^((name|url|email|is_authenticated|profile|userpic|sid|is_trusted|is_author|is_banned|can_post|can_comment):'([^']+?)';?)/)) { 
    241253        s = s.substring(m[1].length); 
    242254        if (m[2].match(/^(is|can)_/)) // boolean fields 
     
    286298 */ 
    287299</mt:Ignore> 
     300var mtFetchedUser = false; 
    288301function mtFetchUser(cb) { 
    289302    if (!cb) cb = 'mtSetUser'; 
     
    296309        // we aren't using AJAX for this, since we may have to request 
    297310        // from a different domain. JSONP to the rescue. 
     311        mtFetchedUser = true; 
    298312        var script = document.createElement('script'); 
    299313        script.src = '<$mt:CGIPath$><$mt:CommentScript$>?__mode=session_js&blog_id=<$mt:BlogID$>&jsonp=' + cb; 
     
    337351        if (f.preview_button) f.preview_button.disabled = true; 
    338352        if (f.post) f.post.disabled = true; 
     353 
     354        var u = mtGetUser(); 
     355        if ( !is_preview && ( u && u.is_authenticated ) ) { 
     356            // validate session; then submit 
     357            mtFetchedUser = false; 
     358            mtFetchUser('mtCommentSessionVerify'); 
     359            return false; 
     360        } 
     361 
    339362        return true; 
    340363    } 
    341364    return false; 
     365} 
     366 
     367function mtCommentSessionVerify(app_user) { 
     368    var u = mtGetUser(); 
     369    var f = document['comments_form']; 
     370    if ( u && app_user && app_user.sid && ( u.sid == app_user.sid ) ) { 
     371        f.submit(); 
     372    } else { 
     373        alert('<__trans phrase="Your session has expired. Please sign in again to comment." escape="js">'); 
     374        mtClearUser(); 
     375        mtFireEvent('usersignin'); 
     376<mt:IfRegistrationRequired> 
     377        mtShow('comments-form'); 
     378        mtHide('comments-open-footer'); 
     379</mt:IfRegistrationRequired> 
     380    } 
    342381} 
    343382 
     
    377416                if (cf.bakecookie) 
    378417                    cf.bakecookie.checked = u.name || u.email; 
     418            } else { 
     419                if (u && u.sid && cf.sid) 
     420                    cf.sid.value = u.sid; 
    379421            } 
    380             if (cf.post.disabled) { 
     422            if (cf.post.disabled) 
    381423                cf.post.disabled = false; 
    382                 cf.post.value = '<__trans phrase="Submit">'; 
    383             } 
    384             if (cf.preview_button.disabled) { 
     424            if (cf.preview_button.disabled) 
    385425                cf.preview_button.disabled = false; 
    386                 cf.preview_button.value = '<__trans phrase="Preview">'; 
    387             } 
     426            mtRequestSubmitted = false; 
    388427        } 
    389428    } 
     
    478517    var reg_reqd = <mt:IfRegistrationRequired>true<mt:Else>false</mt:IfRegistrationRequired>; 
    479518 
    480     var cf = document.comments_form; 
     519    var cf = document['comments_form']; 
    481520    if (!cf) return; 
    482521 
     
    615654</mt:Ignore> 
    616655function mtClearUser() { 
     656    user = null; 
    617657    mtDeleteCookie(mtCookieName, mtCookiePath, mtCookieDomain, 
    618658        location.protocol == 'https:');