root/branches/release-38/extras/examples/plugins/CommentByGoogleAccount/lib/CommentByGoogleAccount.pm @ 2365

Revision 2365, 2.1 kB (checked in by bchoate, 19 months ago)

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

  • Property svn:keywords set to Id Author Date Revision
Line 
1# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
2# This program is distributed under the terms of the
3# GNU General Public License, version 2.
4#
5# $Id$
6
7# CommentByGoogleAccount plugin for Movable Type
8# Author: Six Apart (http://www.sixapart.com)
9# Released under the Artistic and GPLv2 License
10
11package CommentByGoogleAccount;
12use strict;
13
14use base qw(MT::ErrorHandler);
15use MT::Util qw( escape_unicode );
16use MT::I18N qw( encode_text );
17
18## Google does not give third party applications access to these data...
19my $nick = 'I am Google';
20my $email = q();
21my $url = 'http://www.google.com/';
22my $name = $nick;
23
24sub handle_sign_in {
25    my $class = shift;
26    my ($app, $auth_type) = @_;
27    my $q = $app->{query};
28   
29    my $sys_config = MT::Plugin::CommentByGoogleAccount->instance->get_config_hash;
30    my $nick = $sys_config->{google_commenter_nickname} || 'Google Account';
31
32    my $cmntr;
33    my $session;
34
35    if ($q->param('token')) {
36        # Redirected == Authenticated in Google Account API.
37
38        my $enc = $app->{cfg}->PublishCharset || '';
39        my $nick_escaped = escape_unicode($nick);
40        $nick = encode_text($nick, 'utf-8', undef);
41        $cmntr = $app->_make_commenter(
42            email => $email,
43            nickname => $nick,
44            name => $name,
45            url => $url,
46            auth_type => $auth_type,
47        );
48
49        $session = $app->make_commenter_session($cmntr);
50        unless ($session) {
51            $app->error($app->errstr() || $app->translate("Couldn't save the session"));
52            return 0;
53        }
54    } else {
55        # If there's no signature, then we trust the cookie.
56        my %cookies = $app->cookies();
57        if ($cookies{$app->COMMENTER_COOKIE_NAME()}
58            && ($session = $cookies{$app->COMMENTER_COOKIE_NAME()}->value())) 
59        {
60            require MT::Session;
61            require MT::Author;
62            my $sess = MT::Session->load({id => $session});
63            $cmntr = MT::Author->load({name => $sess->name,
64                                       type => MT::Author::COMMENTER()});
65        }
66    }
67    if ($q->param('token') && !$cmntr) {
68        return 0;
69    }
70    return $cmntr;
71}
Note: See TracBrowser for help on using the browser.