Revision 243 (by ahitrov, 2012/09/13 18:29:46) oAuth: Facebook, Vkontakte, Mail.ru
<script type="text/javascript">
<!--
opener.location.reload(true);
close();
//-->
</script>
<%doc>
<pre><% Dumper($user_info) %></pre>
</%doc>
<%doc>

   use LWP::UserAgent;
   use JSON::XS;
   use URI;
   use Encode;
   use URI;
   use URI::QueryParam;
   my $JSON = JSON::XS->new->utf8;

Manual redirect:
   use session::AUTH::Mailru;
   my $site = $state->development ? 'www' : 'www';
   my $mail_connect = session::AUTH::Mailru->new(
		mail_redirect_uri   => 'http://'.$site.'/auth/mailru.html',
	);


</%doc>
<%once>

   my $site = $state->development ? '' : '';
   use session::AUTH::Mailru;

</%once>
<%args>

	$code	=> undef

</%args>
<%init>

   my $res;
   my $info;

   my $mail_connect = session::AUTH::Mailru->new;
   my $auth_url = $mail_connect->authorize_url;
   if ( $code ) {
	my $local_session = $mail_connect->authenticate( code => $code );
	if ( ref $local_session && exists $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;
				$keeper->{session}->store_value (
					name    => $profile->name_full,
					last_name       => $profile->name_family,
					first_name      => $profile->name_part,
					avatar  => $session->{avatar},
				);
			} else {
				$keeper->{session}->store_value (
					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>