mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-12-24 07:10 am

[dw-free] Convert htdocs/pubkey.bml to TT

[commit: http://hg.dwscoalition.org/dw-free/rev/6d147672fb7f]

http://bugs.dwscoalition.org/show_bug.cgi?id=2249

Templatetoolkitize htdocs/pubkey.bml. Adds new option specify_user to
controller base method.

Patch by [staff profile] mark.

Files modified:
  • bin/upgrading/en.dat
  • cgi-bin/DW/Controller.pm
  • cgi-bin/DW/Controller/Misc.pm
  • htdocs/pubkey.bml
  • htdocs/pubkey.bml.text
  • views/misc/pubkey.tt
  • views/misc/pubkey.tt.text
--------------------------------------------------------------------------------
diff -r 304d266c3019 -r 6d147672fb7f bin/upgrading/en.dat
--- a/bin/upgrading/en.dat	Wed Dec 23 13:26:20 2009 -0600
+++ b/bin/upgrading/en.dat	Thu Dec 24 07:10:54 2009 +0000
@@ -1176,6 +1176,8 @@ error.invalidauth=You could not be authe
 error.invalidauth=You could not be authenticated as the specified user.
 
 error.invalidform=Invalid form submission.  Please refresh and try again.
+
+error.invaliduser=Unable to load specified user.
 
 error.ipbanned=Your IP address is temporarily banned for exceeding the login failure rate.
 
diff -r 304d266c3019 -r 6d147672fb7f cgi-bin/DW/Controller.pm
--- a/cgi-bin/DW/Controller.pm	Wed Dec 23 13:26:20 2009 -0600
+++ b/cgi-bin/DW/Controller.pm	Thu Dec 24 07:10:54 2009 +0000
@@ -60,14 +60,22 @@ sub controller {
 
     # 'anonymous' pages must declare themselves, else we assume that a remote is
     # necessary as most pages require a user
+    $vars->{u} = $vars->{remote} = LJ::get_remote();
     unless ( $args{anonymous} ) {
-        $vars->{u} = $vars->{remote} = LJ::get_remote()
+        $vars->{remote}
             or return $fail->( needlogin() );
+    }
+
+    # if they can specify a user argument, try to load that
+    my $r = DW::Request->get;
+    if ( $args{specify_user} ) {
+        # use 'user' argument if specified, default to remote
+        $vars->{u} = LJ::load_user( $r->get_args->{user} ) || $vars->{remote}
+            or return $fail->( error_ml( 'error.invaliduser' ) );
     }
 
     # if a page allows authas it must declare it.  authas can only happen if we are
     # requiring the user to be logged in.
-    my $r = DW::Request->get;
     if ( $args{authas} ) {
         $vars->{u} = LJ::get_authas_user( $r->get_args->{authas} || $vars->{remote}->user )
             or return $fail->( error_ml( 'error.invalidauth' ) );
diff -r 304d266c3019 -r 6d147672fb7f cgi-bin/DW/Controller/Misc.pm
--- a/cgi-bin/DW/Controller/Misc.pm	Wed Dec 23 13:26:20 2009 -0600
+++ b/cgi-bin/DW/Controller/Misc.pm	Thu Dec 24 07:10:54 2009 +0000
@@ -26,6 +26,7 @@ use DW::Template::Apache2;
 use DW::Template::Apache2;
 
 DW::Routing::Apache2->register_string( '/misc/whereami', \&whereami_handler, app => 1 );
+DW::Routing::Apache2->register_string( '/pubkey',        \&pubkey_handler,   app => 1 );
 
 # handles the /misc/whereami page
 sub whereami_handler {
@@ -39,4 +40,16 @@ sub whereami_handler {
     return DW::Template::Apache2->render_template( 'misc/whereami.tt', $vars );
 }
 
+# handle requests for a user's public key
+sub pubkey_handler {
+    return error_ml( '.error.notconfigured' ) unless $LJ::USE_PGP;
+
+    my ( $ok, $rv ) = controller( anonymous => 1, specify_user => 1 );
+    return $rv unless $ok;
+
+    LJ::load_user_props( $rv->{u}, 'public_key' );
+
+    return DW::Template::Apache2->render_template( 'misc/pubkey.tt', $rv );
+}
+
 1;
diff -r 304d266c3019 -r 6d147672fb7f htdocs/pubkey.bml
--- a/htdocs/pubkey.bml	Wed Dec 23 13:26:20 2009 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-<?page
-title=><?_ml .title _ml?>
-head<=
-
-<style type="text/css">
-
-    .key
-    {
-        background-color:#efefef;
-        border:3px solid #dedede;
-        padding:10px;
-    }
-
-</style>
-
-<=head
-body<=
-<?_code
-{
-    use strict;
-    use vars qw(%GET $user $u $ret);
-
-    return $ML{'.error.notconfigured'} unless $LJ::USE_PGP;
-    return LJ::server_down_html() if $LJ::SERVER_DOWN;
-
-    $user = LJ::canonical_username($GET{user});
-    $u = $user ? LJ::load_user($user) : LJ::get_remote();
-    return $ML{'.error.nousername'} unless $user || $u;
-
-    LJ::load_user_props($u, 'public_key');
-   
-    if ($u->{public_key}) {
-        $ret .= '<?p ' . BML::ml('.label', { user => LJ::ljuser($u->{user})}) . ' p?>';
-        $ret .= "<table border=0><tr><td class=key><pre>\n";
-        $ret .= LJ::ehtml($u->{public_key});
-        $ret .= "\n</pre></td></tr></table>";
-    } else {
-        $ret .= '<?p ' . BML::ml('.nokey', { user => LJ::ljuser($u->{user})}) . ' p?>';
-    }
-    $ret .= "<br /><?h1 $ML{'.info.head'} h1?>";
-    $ret .= "<?p ";
-    $ret .= BML::ml('.info.desc', {
-        aoptspgp => 'href="http://www.pgp.com/"',
-        aoptsgpg => 'href="http://www.gnupg.org/"',
-    });
-    $ret .= " p?> <?p ";
-    $ret .= BML::ml('.info.upload', {
-        aopts => 'href="/manage/pubkey"',
-    });
-    $ret .= " p?>";
-    return $ret;
-
-} _code?>
-<=body
-page?>
diff -r 304d266c3019 -r 6d147672fb7f htdocs/pubkey.bml.text
--- a/htdocs/pubkey.bml.text	Wed Dec 23 13:26:20 2009 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-;; -*- coding: utf-8 -*-
-.error.notconfigured=This site is not configured with PGP support.
-
-.error.nousername=No username specified.
-
-.info.desc=Don't know what a public key is?  Read more about <a [[aoptspgp]]>PGP</a> and <a [[aoptsgpg]]>GPG</a>.
-
-.info.head=Information
-
-.info.upload=Want to upload your key?  Click <a [[aopts]]>here</a>.
-
-.label=Public key for [[user]]:
-
-.nokey=[[user]] has not uploaded a public key yet.
-
-.title=View Public Key
-
diff -r 304d266c3019 -r 6d147672fb7f views/misc/pubkey.tt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/misc/pubkey.tt	Thu Dec 24 07:10:54 2009 +0000
@@ -0,0 +1,20 @@
+<h1>[% '.title' | ml %]</h1>
+
+[% IF u.public_key %]
+    <p>[% '.label' | ml(user = u.ljuser_display) %]</p>
+    <pre style='background-color:#efefef; border:3px solid #dedede; padding: 10px;'>
+        [% u.public_key | html %]
+    </pre>
+[% ELSE %]
+    <p>[% '.nokey' | ml(user = u.ljuser_display) %]</p>
+[% END %]
+
+<br />
+
+<h1>[% '.info.head' | ml %]</h1>
+
+<p>[% '.info.desc' | ml(aoptspgp = "href='http://www.pgp.com/'", aoptsgpg = "href='http://www.gnupg.org/'") %]</p>
+
+[% IF remote %]
+    <p>[% '.info.upload' | ml(aopts = "href='$roots.site/manage/pubkey'") %]</p>
+[% END %]
diff -r 304d266c3019 -r 6d147672fb7f views/misc/pubkey.tt.text
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/misc/pubkey.tt.text	Thu Dec 24 07:10:54 2009 +0000
@@ -0,0 +1,17 @@
+;; -*- coding: utf-8 -*-
+.error.notconfigured=This site is not configured with PGP support.
+
+.error.nousername=No username specified.
+
+.info.desc=Don't know what a public key is?  Read more about <a [[aoptspgp]]>PGP</a> and <a [[aoptsgpg]]>GPG</a>.
+
+.info.head=Information
+
+.info.upload=Want to upload your key?  Click <a [[aopts]]>here</a>.
+
+.label=Public key for [[user]]:
+
+.nokey=[[user]] has not uploaded a public key yet.
+
+.title=View Public Key
+
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org