Revision 281 (by ahitrov, 2013/02/19 14:45:34) Session object implemented
<script type="text/javascript">
<!--
opener.location.reload(true);
close();
//-->
</script>
<%doc>

Manual redirect:

   use session::AUTH::FaceBook;
   my $site = $state->development ? 'www' : 'www';
   my $fb_connect = session::AUTH::FaceBook->new(
		facebook_redirect_uri   => 'http://'.$site.'/oauth/facebook.html',
	);

</%doc>
<%args>

	$code	=> undef
	$state	=> undef

</%args>
<%init>

   my $fb_connect = session::AUTH::FaceBook->new();
   my $auth_url = $fb_connect->authorize_url( state => $state );
   if ( $code ) {
	my $local_session = $fb_connect->authenticate( code => $code, state => $state );
	if ( ref $local_session eq 'session::Session' && $local_session->id ) {
		my $profile = $keeper->{users}->get_profile( id => $local_session->{id} )	if exists $keeper->{users};
		if ( ref $profile ) {
			unless ( exists $local_session->{avatar} ) {
				my $avatar = $profile->get_image('avatar');
				$session->{avatar} = ref $avatar && exists $avatar->{filename} ? $avatar->{mini}{'54x54'}{filename} : undef;
				$local_session->set (
					name    => $profile->name_full,
					last_name       => $profile->name_family,
					first_name      => $profile->name_part,
					avatar  => $session->{avatar},
				);
			} else {
				$local_session->set (
					name    => $profile->name_full,
					last_name       => $profile->name_family,
					first_name      => $profile->name_part,
				);
			}
		}
	}
   } elsif ( $auth_url ) {
	$m->redirect($auth_url->as_string);
   } else {
	&abort404	unless $DEBUG;
   }

</%init>