root/branches/release-36/extras/examples/plugins/CommentByGoogleAccount/lib/CommentByGoogleAccount.pm @ 2062

Revision 2062, 2.2 kB (checked in by bchoate, 19 months ago)

Updates to blog-side javascript regarding user state and permissions. BugId:79077,69644,67754,69814,79258,62643. Fixed declarations for conditional tags. BugId:79476. Display auth'd user nickname rather than name from comment object. BugId:79475

  • 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        $session = $app->make_commenter_session($app->make_magic_token, $email,
42                                                 $name, $nick_escaped);
43        unless ($session) {
44            $app->error($app->errstr() || $app->translate("Couldn't save the session"));
45            return 0;
46        }
47        $cmntr = $app->_make_commenter(
48            email => $email,
49            nickname => $nick,
50            name => $name,
51            url => $url,
52            auth_type => $auth_type,
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.