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