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.pm

    r2322 r2365  
    1212use File::Spec; 
    1313use MT::Request; 
    14 use MT::Util qw( encode_html offset_time_list decode_html encode_url is_valid_email is_url ); 
     14use MT::Util qw( encode_html offset_time_list decode_html encode_url 
     15    is_valid_email is_url escape_unicode ); 
    1516use MT::I18N qw( encode_text wrap_text ); 
    1617 
     
    10171018sub make_commenter_session { 
    10181019    my $app = shift; 
    1019     my ($session_key, $email, $name, $nick, $id, $url, $timeout, $blog_id) = @_; 
     1020    my ($session_key, $email, $name, $nick, $id, $url) = @_; 
     1021    my $user; 
     1022 
     1023    # support for old signature; new signature is $session_key, $user_obj 
     1024    if ( ref($session_key) && $session_key->isa('MT::Author') ) { 
     1025        $user = $session_key; 
     1026        $session_key = $app->make_magic_token; 
     1027        $email = $user->email; 
     1028        $name = $user->name; 
     1029        $nick = $user->nickname || $app->translate('(Display Name not set)'); 
     1030        $id = $user->id; 
     1031        $url = $user->url; 
     1032    } 
     1033    # test 
     1034    $session_key = $app->param('sig') if $user->auth_type eq 'TypeKey'; 
     1035 
     1036    require MT::Session; 
     1037    my $sess_obj = MT::Session->new(); 
     1038    $sess_obj->id($session_key); 
     1039    $sess_obj->email($email); 
     1040    $sess_obj->name($name); 
     1041    $sess_obj->start(time); 
     1042    $sess_obj->kind("SI"); 
     1043    $sess_obj->set('author_id', $user->id) if $user; 
     1044    $sess_obj->save() 
     1045        or return $app->error($app->translate("The login could not be confirmed because of a database error ([_1])", $sess_obj->errstr)); 
    10201046 
    10211047    my $enc = $app->charset; 
     
    10231049    my $nick_escaped = MT::Util::escape_unicode( $nick ); 
    10241050 
    1025     $timeout = '+' . $app->config->CommentSessionTimeout . 's' unless defined $timeout; 
     1051    my $timeout; 
     1052    if ( $user->auth_type eq 'MT' ) { 
     1053        $timeout = '+' . $app->config->UserSessionTimeout . 's'; 
     1054    } else { 
     1055        $timeout = '+' . $app->config->CommentSessionTimeout . 's'; 
     1056    } 
     1057 
    10261058    my %kookee = (-name => COMMENTER_COOKIE_NAME(), 
    10271059                  -value => $session_key, 
     
    10341066                       ($timeout ? (-expires => $timeout) : ())); 
    10351067    $app->bake_cookie(%name_kookee); 
    1036     if (defined $id) { 
    1037         my $banned = 0; 
    1038         my $perm = MT::Permission->load({ blog_id => $blog_id, author_id => $id }); 
    1039         if ($perm) { 
    1040             if (!$perm->can_administer_blog && $perm->is_restricted('comment')) { 
    1041                 $banned = 1; 
    1042             } 
    1043         } 
    1044  
    1045         # my %id_kookee = (-name => "commenter_id", 
    1046         #                    -value => $id . ':' . $blog_ids, 
    1047         #                    -path => '/', 
    1048         #                    ($timeout ? (-expires => $timeout) : ())); 
    1049         # $app->bake_cookie(%id_kookee); 
    1050     } 
    1051     # if (defined($url) && $url) { 
    1052     #     my %id_kookee = (-name => "commenter_url", 
    1053     #                        -value => $url, 
    1054     #                        -path => '/', 
    1055     #                        ($timeout ? (-expires => $timeout) : ())); 
    1056     #     $app->bake_cookie(%id_kookee); 
    1057     # } 
    1058  
    1059     require MT::Session; 
    1060     my $sess_obj = MT::Session->new(); 
    1061     $sess_obj->id($session_key); 
    1062     $sess_obj->email($email); 
    1063     $sess_obj->name($name); 
    1064     $sess_obj->start(time); 
    1065     $sess_obj->kind("SI"); 
    1066     $sess_obj->save() 
    1067         or return $app->error($app->translate("The login could not be confirmed because of a database error ([_1])", $sess_obj->errstr)); 
     1068 
    10681069    return $session_key; 
    10691070} 
     
    10841085 
    10851086    # need to clear commenter_name for writeCommenterGreeting 
    1086     my $timeout = $app->config->CommentSessionTimeout; 
    10871087    my %name_kookee = (-name => 'commenter_name', 
    10881088                       -value => '', 
    10891089                       -path => '/', 
    1090                        -expires => "+${timeout}s"); 
     1090                       -expires => "Thu, 01-Jan-70 00:00:01 GMT"); 
    10911091    $app->bake_cookie(%name_kookee); 
    1092  
    1093     # my %kookee = (-name => COMMENTER_COOKIE_NAME(), 
    1094     #               -value => '', 
    1095     #               -path => '/', 
    1096     #               -expires => "+${timeout}s"); 
    1097     # $app->bake_cookie(%kookee); 
    1098     # my %url_kookee = (-name => 'commenter_url', 
    1099     #                    -value => '', 
    1100     #                    -path => '/', 
    1101     #                    -expires => "+${timeout}s"); 
    1102     # $app->bake_cookie(%url_kookee); 
    1103     # my %id_kookee = (-name => 'commenter_id', 
    1104     #                    -value => '', 
    1105     #                    -path => '/', 
    1106     #                    -expires => "+${timeout}s"); 
    1107     # $app->bake_cookie(%id_kookee); 
     1092    my %kookee = (-name => COMMENTER_COOKIE_NAME(), 
     1093                  -value => '', 
     1094                  -path => '/', 
     1095                  -expires => "Thu, 01-Jan-70 00:00:01 GMT"); 
     1096    $app->bake_cookie(%kookee); 
    11081097} 
    11091098 
     
    14491438                # Presence of 'password' indicates this is a login request; 
    14501439                # do session/cookie management. 
    1451                 $app->make_commenter_session( 
    1452                     $app->make_magic_token,  
    1453                     $author->email,  
    1454                     $author->name,  
    1455                     ($author->nickname || $app->translate('(Display Name not set)')),  
    1456                     $author->id,  
    1457                     undef,  
    1458                     $ctx->{permanent} ? '+10y' : 0 
    1459                 ); 
     1440                $app->make_commenter_session($author); 
    14601441 
    14611442                if ($commenter_blog_id) {