1 |
243 |
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 |
|
|
use session::AUTH::VKontakte; |
22 |
|
|
my $site = $state->development ? 'www' : 'www'; |
23 |
|
|
my $vk_connect = session::AUTH::VKontakte->new( |
24 |
281 |
ahitrov |
vk_redirect_uri => 'http://'.$site.'/oauth/vkontakte.html', |
25 |
243 |
ahitrov |
); |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
</%doc> |
29 |
|
|
<%once> |
30 |
|
|
|
31 |
|
|
my $site = $state->development ? '' : ''; |
32 |
|
|
|
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 |
281 |
ahitrov |
if ( ref $local_session eq 'session::Session' && $local_session->id ) { |
49 |
243 |
ahitrov |
my $profile = $keeper->{users}->get_profile( id => $local_session->{id} ) if exists $keeper->{users}; |
50 |
|
|
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 |
281 |
ahitrov |
$local_session->set ( |
55 |
243 |
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 |
281 |
ahitrov |
$local_session->set ( |
62 |
243 |
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> |