Line # Revision Author
1 246 ahitrov <script type="text/javascript">
2 <!--
3 opener.location.reload(true);
4 close();
5 //-->
6 </script>
7 <pre><% Dumper($google_connect) %></pre>
8 <%doc>
9
10 use LWP::UserAgent;
11 use JSON::XS;
12 use URI;
13 use Encode;
14 use URI;
15 use URI::QueryParam;
16 my $JSON = JSON::XS->new->utf8;
17
18 Manual redirect:
19 use session::AUTH::Google;
20 my $site = $state->development ? 'www' : 'www';
21 my $google_connect = session::AUTH::Google->new(
22 google_redirect_uri => 'http://'.$site.'/oauth/google.html',
23 );
24
25
26 </%doc>
27 <%once>
28
29 my $site = $state->development ? '' : '';
30 use session::AUTH::Google;
31
32 </%once>
33 <%args>
34
35 $code => undef
36
37 </%args>
38 <%init>
39
40 my $res;
41 my $info;
42
43 my $google_connect = session::AUTH::Google->new;
44 my $auth_url = $google_connect->authorize_url;
45 if ( $code ) {
46 my $local_session = $google_connect->authenticate( code => $code );
47 if ( ref $local_session && exists $local_session->{id} ) {
48 my $profile = $keeper->{users}->get_profile( id => $local_session->{id} ) if exists $keeper->{users};
49 if ( ref $profile ) {
50 unless ( exists $local_session->{avatar} ) {
51 my $avatar = $profile->get_image('avatar');
52 $session->{avatar} = ref $avatar && exists $avatar->{filename} ? $avatar->{mini}{'54x54'}{filename} : undef;
53 $keeper->{session}->store_value (
54 name => $profile->name_full,
55 last_name => $profile->name_family,
56 first_name => $profile->name_part,
57 avatar => $session->{avatar},
58 );
59 } else {
60 $keeper->{session}->store_value (
61 name => $profile->name_full,
62 last_name => $profile->name_family,
63 first_name => $profile->name_part,
64 );
65 }
66 }
67 }
68 } elsif ( $auth_url ) {
69 $m->redirect($auth_url->as_string);
70 } else {
71 &abort404 unless $DEBUG;
72 }
73
74 </%init>