]> www.wagner.pp.ru Git - oss/vjournal.git/blob - bin/userinfo
new description
[oss/vjournal.git] / bin / userinfo
1 #!/usr/bin/perl -T
2
3 =head1 NAME
4
5 vjuserinfo - return current user info as json
6
7 =head1 SYNOPSIS
8
9         http://your.server.org/cgi-bin/vjuserinfo/your-blog-top
10
11 =head1 DESCRIPTION
12
13 Returns info about current user using following format
14         
15         { 
16                 url:"somebody.livejournal.com",
17                 displayname:"somebody@lj",
18                 state: "guest",
19                 avatar: {src: "http://your.server.org/avatars/somebody@lj.gif",
20                 width:100, height:100},
21         }
22
23 B<state> can be B<owner>, B<guest> or B<banned>.
24
25 If user is not logged in, returns following structure:
26
27     {
28                 state: "notlogged",
29                 providers: [
30                         {name: "Live journal",icon:"/avatars/lj.gif",id: "lj"}
31             ...
32         }
33
34 =cut
35
36 use VJournal::Session;
37 use VJournal::ProviderList;
38 use JSON;
39 use CGI;
40
41 my $cgi=new CGI;
42 my $session = VJournal::Session->new($cgi);
43 my $out={};
44 if (!defined $session) {
45 # User is not authenticated. Return list of providers;
46         $out->{state}="notlogged";
47         $sites=VJournal::ProviderList->new;
48         $out->{providers}=[ $sites->menu ] ;
49         $session=$cgi;
50 } else {
51         if ($session->isowner())  {
52                 $out->{state}="owner";
53         } elsif ($session->banned()) {
54                 $out->{state}="banned";
55         } else {
56                 $out->{state}="guest";
57         }
58
59         $out->{url}=$session->identity();
60         $out->{displayname}=$session->name();
61         %avatar=$session->avatar();
62         if(exists $avatar{-src}) {
63                 $out->{avatar}={src=>$avatar{-src},-width=>$avatar{-width},
64                                 -height=>$avatar{-height}};
65         }                       
66                 
67 }
68 print $session->header(-content_type=>"text/json",-charset=>"utf-8");
69 print encode_json($out);
70