pretty openid login
authorJoey Hess <joey@kitenet.net>
Sat, 8 May 2010 00:14:25 +0000 (20:14 -0400)
committerJoey Hess <joey@kitenet.net>
Sat, 8 May 2010 00:14:25 +0000 (20:14 -0400)
* openid: Incorporated a fancy openid-selector signin form.
  (http://code.google.com/p/openid-selector/)
* openid: Use "openid_identifier" as the form field, as required
  by OpenID Authentication v2.0 spec.

IkiWiki/Plugin/openid.pm
debian/changelog
debian/copyright
doc/style.css
t/openiduser.t
t/permalink.t
templates/openid-selector.tmpl
underlays/openid-selector/ikiwiki/openid/jquery.js [moved from underlays/javascript/ikiwiki/openid-selector/jquery.js with 100% similarity]
underlays/openid-selector/ikiwiki/openid/openid-jquery.js [moved from underlays/javascript/ikiwiki/openid-selector/openid-jquery.js with 100% similarity]

index 0ad8697..e722c68 100644 (file)
@@ -7,6 +7,7 @@ use strict;
 use IkiWiki 3.00;
 
 sub import {
+       add_underlay("openid-selector");
        hook(type => "checkconfig", id => "openid", call => \&checkconfig);
        hook(type => "getopt", id => "openid", call => \&getopt);
        hook(type => "getsetup", id => "openid", call => \&getsetup);
@@ -19,10 +20,16 @@ sub checkconfig () {
        if ($config{cgi}) {
                # Intercept normal signin form, so the openid selector
                # can be displayed.
-               require IkiWiki::CGI;
-               my $real_cgi_signin=\&IkiWiki::cgi_signin;
+               # 
+               # When other auth hooks are registered, give the selector
+               # a reference to the normal signin form.
+               my $real_cgi_signin;
+               if (keys %{$IkiWiki::hooks{auth}} > 1) {
+                       require IkiWiki::CGI;
+                       $real_cgi_signin=\&IkiWiki::cgi_signin;
+               }
                inject(name => "IkiWiki::cgi_signin", call => sub ($$) {
-                               openid_selector($real_cgi_signin, @_);
+                       openid_selector($real_cgi_signin, @_);
                });
        }
 }
@@ -55,15 +62,21 @@ sub openid_selector {
         my $q=shift;
         my $session=shift;
 
-       my $openid_url=$q->param('openid_url');
+       my $openid_url=$q->param('openid_identifier');
        my $openid_error;
 
-       if (defined $q->param("action") && $q->param("action") eq "verify") {
+       if (! load_openid_module()) {
+               if ($real_cgi_signin) {
+                       $real_cgi_signin->($q, $session);
+               }
+               error(sprintf(gettext("failed to load openid module: "), @_));
+       }
+       elsif (defined $q->param("action") && $q->param("action") eq "verify") {
                validate($q, $session, $openid_url, sub {
                        $openid_error=shift;
                });
        }
-       elsif ($q->param("do") eq "signin" || ! load_openid_module()) {
+       elsif ($q->param("do") eq "signin" && $real_cgi_signin) {
                $real_cgi_signin->($q, $session);
                exit;
        }
@@ -73,8 +86,7 @@ sub openid_selector {
                cgiurl => $config{cgiurl},
                (defined $openid_error ? (openid_error => $openid_error) : ()),
                (defined $openid_url ? (openid_url => $openid_url) : ()),
-               # TODO only if other auth methods are available
-               nonopenidurl => IkiWiki::cgiurl(do => "signin"),
+               ($real_cgi_signin ? (nonopenidurl => IkiWiki::cgiurl(do => "signin")) : ()),
                loginlabel => loginlabel(),
        );
 
@@ -90,45 +102,9 @@ sub formbuilder_setup (@) {
        my $session=$params{session};
        my $cgi=$params{cgi};
        
-       if ($form->title eq "signin") {
-               return unless load_openid_module();
-
-               # This avoids it displaying a redundant label for the
-               # OpenID fieldset.
-               $form->fieldsets("OpenID");
-
-               $form->field(
-                       name => "openid_url",
-                       label => loginlabel(),
-                       fieldset => "OpenID",
-                       size => 30,
-                       comment => ($config{openidsignup} ? " | <a href=\"$config{openidsignup}\">".gettext("Get an OpenID")."</a>" : "")
-               );
-
-               # Handle submission of an OpenID as validation.
-               if ($form->submitted && $form->submitted eq "Login" &&
-                   defined $form->field("openid_url") && 
-                   length $form->field("openid_url")) {
-                       $form->field(
-                               name => "openid_url",
-                               validate => sub {
-                                       validate($cgi, $session, shift, sub {
-                                               # Display error in the form.
-                                               $form->field(name => "openid_url", comment => shift);
-                                       });
-                               },
-                       );
-                       # Skip all other required fields in this case.
-                       foreach my $field ($form->field) {
-                               next if $field eq "openid_url";
-                               $form->field(name => $field, required => 0,
-                                       validate => '/.*/');
-                       }
-               }
-       }
-       elsif ($form->title eq "preferences" &&
+       if ($form->title eq "preferences" &&
               IkiWiki::openiduser($session->param("name"))) {
-               $form->field(name => "openid_url", disabled => 1,
+               $form->field(name => "openid_identifier", disabled => 1,
                        label => htmllink("", "", "ikiwiki/OpenID", noimageinline => 1),
                        value => $session->param("name"), 
                        size => 50, force => 1,
index c335030..3f20aec 100644 (file)
@@ -10,8 +10,10 @@ ikiwiki (3.20100505) UNRELEASED; urgency=low
   * inline: Call indexhtml when inlining internal pages, so their
     text can be indexed for searching.
   * Delete hooks are passed deleted internal pages. 
-  * openid: Incorporated a fancy openid-selector signin form
-    (http://code.google.com/p/openid-selector/).
+  * openid: Incorporated a fancy openid-selector signin form.
+    (http://code.google.com/p/openid-selector/)
+  * openid: Use "openid_identifier" as the form field, as required
+    by OpenID Authentication v2.0 spec.
 
  -- Joey Hess <joeyh@debian.org>  Wed, 05 May 2010 18:07:29 -0400
 
index b6dd378..7ef2661 100644 (file)
@@ -193,11 +193,15 @@ Files: cvs.pm
 Copyright: © 2009 Amitai Schlair
 License: BSD-C2
 
-Files: underlays/javascript/ikiwiki/openid-selector/*
+Files: underlays/openid-selector/ikiwiki/openid/*
 Copyright: © 2008-2010 andyjm, david.j.boden
 License: BSD-C2
   From http://code.google.com/p/openid-selector/
 
+Files: underlays/openid-selector/ikiwiki/openid/jquery.js
+Copyright: © 2005-2008 by John Resig, Branden Aaron & Jörn Zaefferer
+License: GPL-2
+
 License: BSD-C2
  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
index 5f77037..75aa284 100644 (file)
@@ -319,16 +319,6 @@ legend {
        float: left;
        margin: 2px 0;
 }
-#signin_openid_url_label {
-       float: left;
-       margin-right: 1ex;
-}
-#signin_openid {
-       padding: 10px 10px;
-       border: 1px solid #aaa;
-       background: #eee; 
-       color: black !important;
-}
 label.block {    
        display: block;   
 }
@@ -342,13 +332,6 @@ ol.form {
 li.form {
        padding-bottom: 1em;
 }
-input#openid_url {
-       background: url(wikiicons/openidlogin-bg.gif) no-repeat;
-       background-color: #fff;
-       background-position: 0 50%;
-       color: #000;
-       padding-left: 18px;
-}
 input#searchbox {
        background: url(wikiicons/search-bg.gif) no-repeat;
        background-color: #fff;
@@ -440,3 +423,43 @@ li.L8 { list-style: upper-alpha; }
        color: white !important;
        background: #ff9900;
 }
+
+/* openid selector */
+#openid_choice {
+       display: none;
+}
+#openid_input_area {
+       clear: both;
+       padding: 10px;
+}
+#openid_btns, #openid_btns br {
+       clear: both;
+}
+#openid_highlight {
+       padding: 3px;
+       background-color: #FFFCC9;
+       float: left;
+}
+.openid_large_btn {
+       width: 100px;
+       height: 60px;
+       border: 1px solid #DDD;
+       margin: 3px;
+       float: left;
+}
+.openid_small_btn {
+       width: 24px;
+       height: 24px;
+       border: 1px solid #DDD;
+       margin: 3px;
+       float: left;
+}
+a.openid_large_btn:focus {
+       outline: none;
+}
+a.openid_large_btn:focus {
+       -moz-outline-style: none;
+}
+.openid_selected {
+       border: 4px solid #DDD;
+}
index caabbce..7460901 100755 (executable)
@@ -12,7 +12,7 @@ BEGIN {
        else {
                eval q{use Test::More tests => 11};
        }
-       use_ok("IkiWiki::Plugin::openid");
+       use_ok("IkiWiki");
 }
 
 # Some typical examples:
index b49b983..adb8648 100755 (executable)
@@ -5,7 +5,7 @@ use Test::More 'no_plan';
 
 ok(! system("mkdir t/tmp"));
 ok(! system("make -s ikiwiki.out"));
-ok(! system("perl -I. ./ikiwiki.out -plugin inline -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -rss -atom -underlaydir=underlays/basewiki -templatedir=templates t/tinyblog t/tmp/out"));
+ok(! system("perl -I. ./ikiwiki.out -plugin inline -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -rss -atom -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates t/tinyblog t/tmp/out"));
 # This guid should never, ever change, for any reason whatsoever!
 my $guid="http://example.com/post/";
 ok(length `grep '<guid>$guid</guid>' t/tmp/out/index.rss`);
index 76c4051..3934798 100644 (file)
@@ -1,30 +1,29 @@
-<script type="text/javascript" src="ikiwiki/openid-selector/jquery.js"></script>
-<script type="text/javascript" src="ikiwiki/openid-selector/openid-jquery.js"></script>
+<script type="text/javascript" src="ikiwiki/openid/jquery.js"></script>
+<script type="text/javascript" src="ikiwiki/openid/openid-jquery.js"></script>
 <script type="text/javascript">
 $(document).ready(function() {
-       openid.init('openid_url');
+       openid.init('openid_identifier');
 });
 </script>
        
-<TMPL_IF OPENID_ERROR>
-<div class="error"><TMPL_VAR OPENID_ERROR></span>
-</TMPL_IF>
-</div>
-
 <form action="<TMPL_VAR CGIURL>" method="get" id="openid_form">
        <input type="hidden" name="do" value="signin" />
        <input type="hidden" name="action" value="verify" />
-       <div id="openid_choice">
-               <p><TMPL_VAR LOGINLABEL>:</p>
-               <div id="openid_btns">
+       <fieldset>
+               <legend><TMPL_VAR LOGINLABEL></legend>
+               <div id="openid_choice">
+                       <div id="openid_btns">
+                       </div>
+                       <TMPL_IF NONOPENIDURL>
+                       <a href="<TMPL_VAR NONOPENIDURL>">local account</a>
+                       </TMPL_IF>
                </div>
-               <TMPL_IF NONOPENIDURL>
-               <a href="<TMPL_VAR NONOPENIDURL>">local account</a>
+               <div id="openid_input_area">
+                       <input id="openid_identifier" name="openid_identifier" type="text" value="<TMPL_VAR OPENID_URL>"/>
+                       <input id="openid_submit" type="submit" value="Login"/>
+               </div>
+               <TMPL_IF OPENID_ERROR>
+               <div class="error"><TMPL_VAR OPENID_ERROR></div>
                </TMPL_IF>
-       </div>
-       
-       <span id="openid_input_area">
-               <input id="openid_url" name="openid_url" type="text" value="<TMPL_VAR OPENID_URL>"/>
-               <input id="openid_submit" type="submit" value="Login"/>
-       </span>
+       </fieldset>
 </form>