From f8c2a67b3cdbce81bbb661e05411a129b07414ce Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 7 May 2010 20:14:25 -0400 Subject: [PATCH] pretty openid login * 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 | 68 ++++++------------- debian/changelog | 6 +- debian/copyright | 6 +- doc/style.css | 57 +++++++++++----- t/openiduser.t | 2 +- t/permalink.t | 2 +- templates/openid-selector.tmpl | 37 +++++----- .../ikiwiki/openid}/jquery.js | 0 .../ikiwiki/openid}/openid-jquery.js | 0 9 files changed, 91 insertions(+), 87 deletions(-) rename underlays/{javascript/ikiwiki/openid-selector => openid-selector/ikiwiki/openid}/jquery.js (100%) rename underlays/{javascript/ikiwiki/openid-selector => openid-selector/ikiwiki/openid}/openid-jquery.js (100%) diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm index 0ad8697d8..e722c68ba 100644 --- a/IkiWiki/Plugin/openid.pm +++ b/IkiWiki/Plugin/openid.pm @@ -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} ? " | ".gettext("Get an OpenID")."" : "") - ); - - # 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, diff --git a/debian/changelog b/debian/changelog index c335030ed..3f20aec1a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Wed, 05 May 2010 18:07:29 -0400 diff --git a/debian/copyright b/debian/copyright index b6dd3782b..7ef266151 100644 --- a/debian/copyright +++ b/debian/copyright @@ -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 diff --git a/doc/style.css b/doc/style.css index 5f77037e4..75aa28407 100644 --- a/doc/style.css +++ b/doc/style.css @@ -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; +} diff --git a/t/openiduser.t b/t/openiduser.t index caabbcefc..746090103 100755 --- a/t/openiduser.t +++ b/t/openiduser.t @@ -12,7 +12,7 @@ BEGIN { else { eval q{use Test::More tests => 11}; } - use_ok("IkiWiki::Plugin::openid"); + use_ok("IkiWiki"); } # Some typical examples: diff --git a/t/permalink.t b/t/permalink.t index b49b98338..adb8648b4 100755 --- a/t/permalink.t +++ b/t/permalink.t @@ -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' t/tmp/out/index.rss`); diff --git a/templates/openid-selector.tmpl b/templates/openid-selector.tmpl index 76c4051ed..393479865 100644 --- a/templates/openid-selector.tmpl +++ b/templates/openid-selector.tmpl @@ -1,30 +1,29 @@ - - + + - -
- -
-
-
-

:

-
+
+ +
+
+
+ + local account +
- - local account +
+ + +
+ +
-
- - - - - + diff --git a/underlays/javascript/ikiwiki/openid-selector/jquery.js b/underlays/openid-selector/ikiwiki/openid/jquery.js similarity index 100% rename from underlays/javascript/ikiwiki/openid-selector/jquery.js rename to underlays/openid-selector/ikiwiki/openid/jquery.js diff --git a/underlays/javascript/ikiwiki/openid-selector/openid-jquery.js b/underlays/openid-selector/ikiwiki/openid/openid-jquery.js similarity index 100% rename from underlays/javascript/ikiwiki/openid-selector/openid-jquery.js rename to underlays/openid-selector/ikiwiki/openid/openid-jquery.js -- 2.26.2