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/Auth/TypeKey.pm

    r2062 r2365  
    1414    my $class = shift; 
    1515    my ($app, $auth_type) = @_; 
    16     my $q = $app->{query}; 
     16    my $q = $app->param; 
    1717 
    1818    my $sig_str = $q->param('sig'); 
     
    3434    my $cmntr; 
    3535    my $session; 
    36     if ($sig_str) { 
    37         if (!$class->_validate_signature($app, $sig_str,  
    38                                        token => $blog->effective_remote_auth_token, 
    39                                        email => decode_url($email), 
    40                                        name => decode_url($name), 
    41                                        nick => decode_url($nick), 
    42                                        ts => $ts)) 
    43         { 
    44             # Signature didn't match, or timestamp was out of date. 
    45             # This implies tampering, not a user mistake. 
    46             $app->error($app->translate("The sign-in validation failed.")); 
    47             return 0; 
    48         } 
    49  
    50         if ($blog->require_typekey_emails && !is_valid_email($email)) { 
    51             $q->param('email', '');  # blank out email address since it's invalid 
    52             $app->error($app->translate("This weblog requires commenters to pass an email address. If you'd like to do so you may log in again, and give the authentication service permission to pass your email address.")); 
    53             return 0; 
    54         } 
    55  
    56         my $url = $app->{cfg}->IdentityURL; 
    57         $url .= "/" unless $url =~ m|/$|; 
    58         $url .= $name; 
    59  
    60         # Signature was valid, so create a session, etc. 
    61         my $enc = $app->{cfg}->PublishCharset || ''; 
    62         my $nick_escaped = escape_unicode($nick); 
    63         $nick = encode_text($nick, 'utf-8', undef); 
    64         $session = $app->make_commenter_session($sig_str, $email, 
    65                                                  $name, $nick_escaped, undef, $url); 
    66         unless ($session) { 
    67             $app->error($app->errstr() || $app->translate("Couldn't save the session")); 
    68             return 0; 
    69         } 
    70         $cmntr = $app->_make_commenter( 
    71             email => $email, 
    72             nickname => $nick, 
    73             name => $name, 
    74             url => $url, 
    75             auth_type => $auth_type, 
    76         ); 
    77     } else { 
    78         # If there's no signature, then we trust the cookie. 
    79         my %cookies = $app->cookies(); 
    80         my $cookie_name = MT::App::COMMENTER_COOKIE_NAME(); 
    81         if ($cookies{$cookie_name} 
    82             && ($session = $cookies{$cookie_name}->value()))  
    83         { 
    84             require MT::Session; 
    85             require MT::Author; 
    86             my $sess = MT::Session->load({id => $session}) 
    87                 or return 0; 
    88             $cmntr = MT::Author->load({name => $sess->name, 
    89                                        type => MT::Author::COMMENTER(), 
    90                                        auth_type => $auth_type}) 
    91                 or return 0; 
    92             if ($blog->require_typekey_emails 
    93                 && !is_valid_email($cmntr->email)) 
    94             { 
    95                 $app->error($app->translate("This blog requires commenters to provide an email address")); 
    96                 return 0; 
    97             } 
    98         } 
     36 
     37    if (!$class->_validate_signature($app, $sig_str,  
     38                                   token => $blog->effective_remote_auth_token, 
     39                                   email => decode_url($email), 
     40                                   name => decode_url($name), 
     41                                   nick => decode_url($nick), 
     42                                   ts => $ts)) 
     43    { 
     44        # Signature didn't match, or timestamp was out of date. 
     45        # This implies tampering, not a user mistake. 
     46        $app->error($app->translate("The sign-in validation failed.")); 
     47        return 0; 
     48    } 
     49 
     50    if ($blog->require_typekey_emails && !is_valid_email($email)) { 
     51        $q->param('email', '');  # blank out email address since it's invalid 
     52        $app->error($app->translate("This weblog requires commenters to pass an email address. If you'd like to do so you may log in again, and give the authentication service permission to pass your email address.")); 
     53        return 0; 
     54    } 
     55 
     56    my $url = $app->config('IdentityURL'); 
     57    $url .= "/" unless $url =~ m|/$|; 
     58    $url .= $name; 
     59 
     60    # Signature was valid, so create a session, etc. 
     61    $cmntr = $app->_make_commenter( 
     62        email => $email, 
     63        nickname => $nick, 
     64        name => $name, 
     65        url => $url, 
     66        auth_type => $auth_type, 
     67    ); 
     68    $session = $app->make_commenter_session($cmntr); 
     69    unless ($session) { 
     70        $app->error($app->errstr() || $app->translate("Couldn't save the session")); 
     71        return 0; 
    9972    } 
    10073    if ($q->param('sig') && !$cmntr) { 
     
    11285    # the DSA sig parameter is composed of the two pieces of the 
    11386    # real DSA sig, packed in Base64, separated by a colon. 
    114  
    115 #    my ($r, $s) = split /:/, decode_url($sig_str); 
    11687    my ($r, $s) = split /:/, $sig_str; 
    11788    $r =~ s/ /+/g; 
     
    130101    require MT::Util; import MT::Util ('dsa_verify'); 
    131102    my $msg; 
    132     if ($app->{cfg}->TypeKeyVersion eq '1.1') { 
     103    if ($app->config('TypeKeyVersion') eq '1.1') { 
    133104        $msg = ($params{email} . "::" . $params{name} . "::" . 
    134105                $params{nick} . "::" . $params{ts} . "::" . $params{token}); 
     
    150121    if ( ! $dsa_key ) { 
    151122        # Load the override key 
    152         $dsa_key = $app->{cfg}->get('SignOnPublicKey'); 
     123        $dsa_key = $app->config->get('SignOnPublicKey'); 
    153124    } 
    154125    # Load the DSA key from the RegKeyURL 
    155     my $key_location = $app->{cfg}->RegKeyURL; 
     126    my $key_location = $app->config('RegKeyURL'); 
    156127    if (!$dsa_key && $key_location) { 
    157128        my $ua = $app->new_ua;