1 |
239 |
ahitrov |
<script type="text/javascript"> |
2 |
|
|
<!-- |
3 |
240 |
ahitrov |
opener.location.reload(true); |
4 |
239 |
ahitrov |
close(); |
5 |
|
|
//--> |
6 |
|
|
</script> |
7 |
240 |
ahitrov |
%#<pre><% Dumper($fb_connect) %></pre> |
8 |
239 |
ahitrov |
%#<a href="<% $auth_url->as_string %>"><% $auth_url->as_string %></a> |
9 |
240 |
ahitrov |
%#<pre><% Dumper($session) %></pre> |
10 |
239 |
ahitrov |
<%doc> |
11 |
|
|
|
12 |
|
|
Manual redirect: |
13 |
|
|
|
14 |
|
|
use session::AUTH::FaceBook; |
15 |
240 |
ahitrov |
my $site = $state->development ? 'www' : 'www'; |
16 |
239 |
ahitrov |
my $fb_connect = session::AUTH::FaceBook->new( |
17 |
|
|
facebook_redirect_uri => 'http://'.$site.'/oauth/facebook.html', |
18 |
|
|
); |
19 |
|
|
|
20 |
|
|
</%doc> |
21 |
|
|
<%args> |
22 |
|
|
|
23 |
|
|
$code => undef |
24 |
|
|
$state => undef |
25 |
|
|
|
26 |
|
|
</%args> |
27 |
|
|
<%init> |
28 |
|
|
|
29 |
|
|
my $fb_connect = session::AUTH::FaceBook->new(); |
30 |
|
|
my $auth_url = $fb_connect->fb_authorize_url( state => $state ); |
31 |
|
|
if ( $code ) { |
32 |
|
|
my $local_session = $fb_connect->authenticate( code => $code, state => $state ); |
33 |
|
|
if ( ref $local_session && exists $local_session->{id} ) { |
34 |
240 |
ahitrov |
my $profile = $keeper->{users}->get_profile( id => $local_session->{id} ) if exists $keeper->{users}; |
35 |
239 |
ahitrov |
if ( ref $profile ) { |
36 |
|
|
unless ( exists $local_session->{avatar} ) { |
37 |
|
|
my $avatar = $profile->get_image('avatar'); |
38 |
|
|
$session->{avatar} = ref $avatar && exists $avatar->{filename} ? $avatar->{mini}{'54x54'}{filename} : undef; |
39 |
|
|
$keeper->{session}->store_value ( |
40 |
|
|
name => $profile->name_full, |
41 |
|
|
last_name => $profile->name_family, |
42 |
|
|
first_name => $profile->name_part, |
43 |
|
|
avatar => $session->{avatar}, |
44 |
|
|
); |
45 |
|
|
} else { |
46 |
|
|
$keeper->{session}->store_value ( |
47 |
|
|
name => $profile->name_full, |
48 |
|
|
last_name => $profile->name_family, |
49 |
|
|
first_name => $profile->name_part, |
50 |
|
|
); |
51 |
|
|
} |
52 |
|
|
} |
53 |
|
|
} |
54 |
|
|
} elsif ( $auth_url ) { |
55 |
|
|
$m->redirect($auth_url->as_string); |
56 |
|
|
} else { |
57 |
|
|
&abort404 unless $DEBUG; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
</%init> |