Show
Ignore:
Timestamp:
05/16/08 19:51:05 (19 months ago)
Author:
bchoate
Message:

Revised commenter sessions to include user id (as we do with authors) so we can load by id rather than by name. BugId:79253

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-38/lib/MT/App/Comments.pm

    r2350 r2365  
    130130    my $cfg = $app->config; 
    131131    require MT::Session; 
    132     my $sess_obj = MT::Session->load( { id => $session_key } ); 
     132    my $sess_obj = MT::Session->load( { id => $session_key, kind => 'SI' } ); 
    133133    my $timeout = $cfg->CommentSessionTimeout; 
    134     my $user; 
    135      
    136     if ( $sess_obj 
    137         && ( $user = MT::Author->load( { name => $sess_obj->name } ) ) ) 
    138     { 
    139         return ( $session_key, $user ) if $user->type eq MT::Author::AUTHOR(); 
    140     } 
     134    my $user_id = $sess_obj->get('author_id') if $sess_obj; 
     135    my $user = MT::Author->load( $user_id ) if $user_id; 
     136 
    141137    if (   !$sess_obj 
    142138        || ( $sess_obj->start() + $timeout < time ) 
     139        || ( !$user_id ) 
     140        || ( !$user ) 
    143141      ) 
    144142    { 
     143        $app->log("session is invalid; sess_obj = $sess_obj; key = $session_key; user_id = $user_id; user = $user"); 
    145144        $app->_invalidate_commenter_session( \%cookies ); 
    146145        return ( undef, undef ); 
    147146    } 
    148     else { 
    149         # session is valid! 
    150         return ( $session_key, $user ); 
    151     } 
     147 
     148    # session is valid! 
     149    return ( $session_key, $user ); 
    152150} 
    153151 
     
    298296        MT::Auth->new_login( $app, $commenter ); 
    299297        if ( $app->_check_commenter_author( $commenter, $blog_id ) ) { 
    300             $app->make_commenter_session( $app->make_magic_token, 
    301                 $commenter->email, $commenter->name, 
    302                 ($commenter->nickname || $app->translate('(Display Name not set)')), 
    303                 $commenter->id, undef, $ctx->{permanent} ? '+10y' : 0, $blog_id ); 
     298            $app->make_commenter_session( $commenter ); 
    304299            return $app->redirect_to_target; 
    305300        } 
     
    706701        return 0;    # Put a collar on that puppy. 
    707702    } 
     703 
     704    return 1 unless $cfg->ShowIPInformation; 
     705 
     706    # If IP banning is enabled, check for lots of comments from 
     707    # the user's IP within the throttle period * 10; if they 
     708    # exceed 8 comments within that period, ban the IP. 
     709 
    708710    @ts = MT::Util::offset_time_list( time - $throttle_period * 10 - 1, 
    709711        $entry->blog_id ); 
     
    11081110    my $session_key = $cookies{$cookie_name}->value() || ""; 
    11091111    $session_key =~ y/+/ /; 
    1110     my $sessobj = MT::Session->load($session_key); 
     1112    my $sessobj = MT::Session->load({ id => $session_key, kind => 'SI' }); 
    11111113    return 
    11121114      if 
     
    13441346    ); 
    13451347    foreach (@old_sessions) { 
    1346         $_->remove() || die "couldn't remove sessions because " . $_->errstr(); 
     1348        $_->remove(); 
    13471349    } 
    13481350} 
     
    14391441    if ( $blog_id && $blog ) { 
    14401442        my ( $session, $commenter ) = $app->_get_commenter_session(); 
     1443use Data::Dumper; 
    14411444        if ( $session && $commenter ) { 
    14421445            my $blog_perms = $commenter->blog_perm($blog_id); 
     
    14451448            $banned ||= 1 if $commenter->status == MT::Author::BANNED(); 
    14461449 
    1447             my $sessobj = MT::Session->load($session); 
     1450            my $sessobj = MT::Session->load({ id => $session, kind => 'SI' }); 
    14481451            if ($banned) { 
    14491452                $sessobj->remove; 
    14501453            } else { 
    14511454                $sessobj->start( time + 
    1452                     $app->config->CommentSessionTimeout); # extend by timeou 
     1455                    $app->config->CommentSessionTimeout); # extend by timeout 
    14531456                $sessobj->save(); 
    14541457            } 
     
    18211824    } 
    18221825    if ($renew_session) { 
    1823         $app->make_commenter_session( $app->make_magic_token, $cmntr->email, 
    1824             $cmntr->name, 
    1825             ($cmntr->nickname || $app->translate('(Display Name not set)')), 
    1826             $cmntr->id ); 
     1826        $app->make_commenter_session( $cmntr ); 
    18271827    } 
    18281828