]> www.wagner.pp.ru Git - oss/vjournal.git/blob - bin/userinfo
a0dbbdecb0e3c90376fd6f64c50dea48f3ebc50b
[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",format: "%s.livejournal.com"}
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         $session=$cgi;
47 } else {
48         if ($session->isowner())  {
49                 $out->{state}="owner";
50         } elsif ($session->banned()) {
51                 $out->{state}="banned";
52         } else {
53                 $out->{state}="guest";
54         }
55
56         $out->{url}=$session->identity();
57         $out->{displayname}=$session->name();
58         %avatar=$session->avatar();
59         if(exists $avatar{-src}) {
60                 $out->{avatar}={src=>$avatar{-src},-width=>$avatar{-width},
61                                 -height=>$avatar{-height}};
62         }                       
63                 
64 }
65 $session->header(-content_type=>"text/json",-charset=>utf-8);
66 print $encode_json($out);
67