| 111 | | my $q = $app->param; |
| 112 | | |
| 113 | | my $session_key; |
| 114 | | |
| 115 | | my $blog = $app->blog; |
| 116 | | if ($blog) { |
| 117 | | my $auths = $blog->commenter_authenticators || ''; |
| 118 | | if ( $auths =~ /MovableType/ ) { |
| 119 | | # First, check for a real MT user login. If one exists, |
| 120 | | # return that as the commenter identity |
| 121 | | my ($user, $first_time) = $app->SUPER::login(); |
| 122 | | if ( $user ) { |
| 123 | | my $sess = $app->session; |
| 124 | | return ( $sess, $user ); |
| 125 | | } |
| 126 | | } |
| 127 | | } |
| 128 | | |
| 129 | | my %cookies = $app->cookies(); |
| 130 | | my $cookie_name = $app->commenter_cookie; |
| 131 | | if ( !$cookies{$cookie_name} ) { |
| 132 | | return ( undef, undef ); |
| 133 | | } |
| 134 | | $session_key = $cookies{$cookie_name}->value() || ""; |
| 135 | | $session_key =~ y/+/ /; |
| 136 | | my $cfg = $app->config; |
| 137 | | require MT::Session; |
| 138 | | my $sess_obj = MT::Session->load( { id => $session_key, kind => 'SI' } ); |
| 139 | | my $timeout = $cfg->CommentSessionTimeout; |
| 140 | | my $user_id = $sess_obj->get('author_id') if $sess_obj; |
| 141 | | my $user = MT::Author->load( $user_id ) if $user_id; |
| 142 | | |
| 143 | | if ( !$sess_obj |
| 144 | | || ( $sess_obj->start() + $timeout < time ) |
| 145 | | || ( !$user_id ) |
| 146 | | || ( !$user ) |
| 147 | | ) |
| 148 | | { |
| 149 | | $app->_invalidate_commenter_session( \%cookies ); |
| 150 | | return ( undef, undef ); |
| 151 | | } |
| 152 | | |
| 153 | | # session is valid! |
| 154 | | return ( $sess_obj, $user ); |
| 155 | | } |
| 156 | | |
| 157 | | sub login { |
| | 107 | return $app->get_commenter_session(); |
| | 108 | } |
| | 109 | |
| | 110 | sub login_form { |
| 1449 | | sub session_state { |
| 1450 | | my $app = shift; |
| 1451 | | my $blog = $app->blog; |
| 1452 | | my $blog_id = $blog->id if $blog; |
| 1453 | | |
| 1454 | | my $c; |
| 1455 | | if ( $blog_id && $blog ) { |
| 1456 | | my ( $sessobj, $commenter ) = $app->_get_commenter_session(); |
| 1457 | | if ( $sessobj && $commenter ) { |
| 1458 | | my $blog_perms = $commenter->blog_perm($blog_id); |
| 1459 | | my $banned = $commenter->is_banned($blog_id) ? "1" : "0"; |
| 1460 | | $banned = 0 if $blog_perms && $blog_perms->can_administer; |
| 1461 | | $banned ||= 1 if $commenter->status == MT::Author::BANNED(); |
| 1462 | | |
| 1463 | | if ($banned) { |
| 1464 | | $sessobj->remove; |
| 1465 | | } else { |
| 1466 | | $sessobj->start( time + |
| 1467 | | $app->config->CommentSessionTimeout); # extend by timeout |
| 1468 | | $sessobj->save(); |
| 1469 | | } |
| 1470 | | |
| 1471 | | # FIXME: These may not be accurate in 'SingleCommunity' mode... |
| 1472 | | my $can_comment = $banned ? 0 : 1; |
| 1473 | | $can_comment = 0 unless $blog->allow_unreg_comments || $blog->allow_reg_comments; |
| 1474 | | my $can_post = ($blog_perms && $blog_perms->can_create_post) ? "1" : "0"; |
| 1475 | | $c = { |
| 1476 | | sid => $sessobj->id, |
| 1477 | | name => $commenter->nickname, |
| 1478 | | url => $commenter->url, |
| 1479 | | email => $commenter->email, |
| 1480 | | userpic => scalar $commenter->userpic_url, |
| 1481 | | profile => "", # profile link url |
| 1482 | | is_authenticated => "1", |
| 1483 | | is_trusted => ($commenter->is_trusted($blog_id) ? "1" : "0"), |
| 1484 | | is_author => ($commenter->type == MT::Author::AUTHOR() ? "1" : "0"), |
| 1485 | | is_anonymous => "0", |
| 1486 | | is_banned => $banned, |
| 1487 | | can_comment => $can_comment, |
| 1488 | | can_post => $can_post, |
| 1489 | | }; |
| 1490 | | } |
| 1491 | | } |
| 1492 | | |
| 1493 | | unless ($c) { |
| 1494 | | my $can_comment = $blog && $blog->allow_anon_comments ? "1" : "0"; |
| 1495 | | $c = { |
| 1496 | | is_authenticated => "0", |
| 1497 | | is_trusted => "0", |
| 1498 | | is_anonymous => "1", |
| 1499 | | can_post => "0", # no anonymous posts |
| 1500 | | can_comment => $can_comment, |
| 1501 | | is_banned => "0", |
| 1502 | | }; |
| 1503 | | } |
| 1504 | | |
| 1505 | | return $c; |
| 1506 | | } |
| 1507 | | |