Changeset 2393

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

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

Location:
branches/release-38
Files:
4 modified

Legend:

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

    r2191 r2393  
    1616    <mt:ignore><!-- Error message when comment submission fails --></mt:ignore> 
    1717    <MTSetVar name="page_title" value="<__trans phrase="Comment Submission Error">"> 
    18     <MTSetVarBlock name="message"><__trans phrase="Your comment submission failed for the following reasons: [_1]" params="<$MTErrorMessage$>"></MTSetVarBlock> 
     18    <MTSetVarBlock name="message"><p><__trans phrase="Your comment submission failed for the following reasons: [_1]" params="<$MTErrorMessage$>"></p></MTSetVarBlock> 
    1919</MTIf> 
    2020 
  • branches/release-38/default_templates/comments.mtml

    r2376 r2393  
    6161                <input type="hidden" name="armor" value="1" /> 
    6262                <input type="hidden" name="preview" value="" /> 
     63                <input type="hidden" name="sid" value="" /> 
    6364                <div id="comments-open-data"> 
    6465                    <div id="comment-form-name"> 
    6566                        <label for="comment-author"><__trans phrase="Name"></label> 
    66                         <input id="comment-author" name="author" size="30" value="" onfocus="mtShowCaptcha()" /> 
     67                        <input id="comment-author" name="author" size="30" value="" onfocus="mtCommentFormOnFocus()" /> 
    6768                    </div> 
    6869                    <div id="comment-form-email"> 
    6970                        <label for="comment-email"><__trans phrase="Email Address"></label> 
    70                         <input id="comment-email" name="email" size="30" value="" onfocus="mtShowCaptcha()" /> 
     71                        <input id="comment-email" name="email" size="30" value="" onfocus="mtCommentFormOnFocus()" /> 
    7172                    </div> 
    7273                    <div id="comment-form-url"> 
    7374                        <label for="comment-url"><__trans phrase="URL"></label> 
    74                         <input id="comment-url" name="url" size="30" value="" onfocus="mtShowCaptcha()" /> 
     75                        <input id="comment-url" name="url" size="30" value="" onfocus="mtCommentFormOnFocus()" /> 
    7576                    </div> 
    7677                    <div id="comment-form-remember-me"> 
     
    8687                    <label for="comment-text"><__trans phrase="Comments"> 
    8788                    <MTIfAllowCommentHTML><__trans phrase="(You may use HTML tags for style)"></MTIfAllowCommentHTML></label> 
    88                     <textarea id="comment-text" name="text" rows="15" cols="50" onfocus="mtShowCaptcha()"></textarea> 
     89                    <textarea id="comment-text" name="text" rows="15" cols="50" onfocus="mtCommentFormOnFocus()"></textarea> 
    8990                </div> 
    9091                <div id="comments-open-captcha"></div> 
  • 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:'); 
  • branches/release-38/lib/MT/App/Comments.pm

    r2377 r2393  
    114114    my $session_key; 
    115115 
    116     if (my $blog_id = $q->param('blog_id')) { 
    117         if (my $blog = MT::Blog->load($blog_id)) { 
    118             my $auths = $blog->commenter_authenticators || ''; 
    119             if ( $auths =~ /MovableType/ ) { 
    120                 # First, check for a real MT user login. If one exists, 
    121                 # return that as the commenter identity 
    122                 my ($user, $first_time) = $app->SUPER::login(); 
    123                 if ( $user ) { 
    124                     my $sess = $app->session; 
    125                     return ( $sess->id, $user ); 
    126                 } 
     116    my $blog = $app->blog; 
     117    if ($blog) { 
     118        my $auths = $blog->commenter_authenticators || ''; 
     119        if ( $auths =~ /MovableType/ ) { 
     120            # First, check for a real MT user login. If one exists, 
     121            # return that as the commenter identity 
     122            my ($user, $first_time) = $app->SUPER::login(); 
     123            if ( $user ) { 
     124                my $sess = $app->session; 
     125                return ( $sess->id, $user ); 
    127126            } 
    128127        } 
     
    149148      ) 
    150149    { 
    151         $app->log("session is invalid; sess_obj = $sess_obj; key = $session_key; user_id = $user_id; user = $user"); 
    152150        $app->_invalidate_commenter_session( \%cookies ); 
    153151        return ( undef, undef ); 
     
    858856        return $app->handle_error( 
    859857            $app->translate("Comment text is required.") ); 
     858    } 
     859 
     860    # validate session parameter 
     861    if ( my $sid = $q->param('sid') ) { 
     862        my ( $session, $commenter ) = $app->_get_commenter_session(); 
     863        if ( $session && $commenter && ( $session eq $sid ) ) { 
     864            # well, everything is okay 
     865        } else { 
     866            return $app->handle_error( 
     867                $app->translate("Your session has expired. Please sign in again to comment.") 
     868            ); 
     869        } 
    860870    } 
    861871 
     
    14461456    if ( $blog_id && $blog ) { 
    14471457        my ( $session, $commenter ) = $app->_get_commenter_session(); 
    1448 use Data::Dumper; 
    14491458        if ( $session && $commenter ) { 
    14501459            my $blog_perms = $commenter->blog_perm($blog_id); 
     
    14671476            my $can_post = ($blog_perms && $blog_perms->can_create_post) ? "1" : "0"; 
    14681477            $c = { 
     1478                sid => $sessobj->id, 
    14691479                name => $commenter->nickname, 
    14701480                url => $commenter->url,