| 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; |