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