sunnyman's (sunnyman) wrote in changelog,
sunnyman's
sunnyman
changelog

[livejournal] r19244: OPSC-8950: allow_anonymous flag behavior...

Committer: vtroitsky
OPSC-8950: allow_anonymous flag behavior made optional. XMLRPC.getuserpics function added.

U   trunk/cgi-bin/ljprotocol.pl
Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2011-06-07 05:00:07 UTC (rev 19243)
+++ trunk/cgi-bin/ljprotocol.pl	2011-06-07 06:47:56 UTC (rev 19244)
@@ -158,6 +158,7 @@
     unscreencomments  => \&unscreencomments,
     freezecomments    => \&unfreezecomments,
     editcomment       => \&editcomment,
+    getuserpics       => \&getuserpics,
 );
 
 sub translate
@@ -1259,6 +1260,43 @@
     };
 }
 
+sub getuserpics
+{
+    my ($req, $err, $flags) = @_;
+
+    $flags->{allow_anonymous} = 1;
+    return undef unless authenticate($req, $err, $flags);
+    return undef unless check_altusage($req, $err, $flags);
+
+    my $u = $flags->{'u'};
+    my $uowner = $flags->{'u_owner'} || $u;
+    return fail($err, 502) unless $uowner;
+
+    my $res = {
+        xc3 => {
+            u => $u
+        }
+    };
+
+    my $pickws = list_pickws($uowner);
+    @$pickws = sort { lc($a->[0]) cmp lc($b->[0]) } @$pickws;
+    $res->{'pickws'} = [ map { $_->[0] } @$pickws ];
+
+    if ($uowner->{'defaultpicid'}) {
+             $res->{'defaultpicurl'} = "$LJ::USERPIC_ROOT/$uowner->{'defaultpicid'}/$uowner->{'userid'}";
+    }
+    $res->{'pickwurls'} = [ map {
+         "$LJ::USERPIC_ROOT/$_->[1]/$uowner->{'userid'}"
+        } @$pickws ];
+    # validate all text
+    foreach(@{$res->{'pickws'}}) { LJ::text_out(\$_); }
+    foreach(@{$res->{'pickwurls'}}) { LJ::text_out(\$_); }
+    LJ::text_out(\$res->{'defaultpicurl'});
+
+    return $res;
+}
+
+
 sub getfriends
 {
     my ($req, $err, $flags) = @_;
@@ -3897,20 +3935,22 @@
     # see note in ljlib.pl::can_use_journal about why we return
     # both 'ownerid' and 'u_owner' in $flags
 
-    my $alt = $req->{'usejournal'} || $req->{journal};
+    my $alt = $req->{'usejournal'} || $req->{'journal'};
+    my $u = $flags->{'u'};
 
-    if ($flags->{allow_anonymous}) {
-        return fail($err,200) unless $alt;
-        return fail($err,100) unless LJ::canonical_username($alt);
-        $flags->{'u_owner'} = LJ::load_user($alt);
-        $flags->{'ownerid'} = $flags->{'u_owner'}->{'userid'};
-        return 1 if $flags->{'ownerid'};
-        return fail($err,206);
-    }
-
-    my $u = $flags->{'u'};
     unless ($u) {
         my $username = $req->{'username'};
+        unless($username) {
+            if ($flags->{allow_anonymous}) {
+                return fail($err,200) unless $alt;
+                return fail($err,100) unless LJ::canonical_username($alt);
+                $flags->{'u_owner'} = LJ::load_user($alt);
+                $flags->{'ownerid'} = $flags->{'u_owner'}->{'userid'};
+                return 1 if $flags->{'ownerid'};
+                return fail($err,206);
+            }
+            return fail($err,200);
+        }
         return fail($err,200) unless $username;
         return fail($err,100) unless LJ::canonical_username($username);
 

Tags: livejournal, pl, sunnyman
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments