]> www.wagner.pp.ru Git - oss/vjournal.git/blob - bin/userinfo
Added providerlist handling
[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 JSON;
38 use CGI;
39
40 my $cgi=new CGI;
41 my $session = VJourna::Session->new($cgi);
42 my $out={};
43 if (!defined $session) {
44 # User is not authenticated. Return list of providers;
45         $out->{state}="notlogged";
46         $sites=VJournal::ProviderList->new;
47         $out->{providers}=$sites->menu;
48         $session=$cgi;
49 } else {
50         if ($session->isowner())  {
51                 $out->{state}="owner";
52         } elsif ($session->banned()) {
53                 $out->{state}="banned";
54         } else {
55                 $out->{state}="guest";
56         }
57
58         $out->{url}=$session->identity();
59         $out->{displayname}=$session->name();
60         %avatar=$session->avatar();
61         if(exists $avatar{-src}) {
62                 $out->{avatar}={src=>$avatar{-src},-width=>$avatar{-width},
63                                 -height=>$avatar{-height}};
64         }                       
65                 
66 }
67 $session->header(-content_type=>"text/json",-charset=>utf-8);
68 print $encode_json($out);
69