]> wagner.pp.ru Git - oss/vjournal.git/blobdiff - bin/userinfo
output headers for userinfo
[oss/vjournal.git] / bin / userinfo
index 0d92d6943e9d81b4b6ca2e77e6ded9541607ca40..7499a90db1dbc2af445ec3aaf3b3ecb329573d64 100644 (file)
@@ -27,8 +27,44 @@ If user is not logged in, returns following structure:
     {
                state: "notlogged",
                providers: [
-                       {name: "Live journal",icon:"/avatars/lj.gif",format: "%s.livejournal.com"}
+                       {name: "Live journal",icon:"/avatars/lj.gif",id: "lj"}
            ...
        }
 
 =cut
+
+use VJournal::Session;
+use VJournal::ProviderList;
+use JSON;
+use CGI;
+
+my $cgi=new CGI;
+my $session = VJournal::Session->new($cgi);
+my $out={};
+if (!defined $session) {
+# User is not authenticated. Return list of providers;
+       $out->{state}="notlogged";
+       $sites=VJournal::ProviderList->new;
+       $out->{providers}=[ $sites->menu ] ;
+       $session=$cgi;
+} else {
+       if ($session->isowner())  {
+               $out->{state}="owner";
+       } elsif ($session->banned()) {
+               $out->{state}="banned";
+       } else {
+               $out->{state}="guest";
+       }
+
+       $out->{url}=$session->identity();
+       $out->{displayname}=$session->name();
+       %avatar=$session->avatar();
+       if(exists $avatar{-src}) {
+               $out->{avatar}={src=>$avatar{-src},-width=>$avatar{-width},
+                               -height=>$avatar{-height}};
+       }                       
+               
+}
+print $session->header(-content_type=>"text/json",-charset=>"utf-8");
+print encode_json($out);
+