From c3e9215e1fcb604c3ee01119fdf7cf13724c3812 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 8 May 2010 15:57:39 -0400 Subject: [PATCH] moved non-openid signin form into same page as openid selector; show/hide as buttons are pressed --- IkiWiki/CGI.pm | 23 +++++++++++--- IkiWiki/Plugin/openid.pm | 6 +--- templates/openid-selector.tmpl | 31 ++++++++++--------- .../ikiwiki/openid/openid-jquery.js | 27 ++++++++++++---- 4 files changed, 57 insertions(+), 30 deletions(-) diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 49a505514..b98e9e0a1 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -22,7 +22,7 @@ sub printheader ($) { } } -sub showform ($$$$;@) { +sub prepform { my $form=shift; my $buttons=shift; my $session=shift; @@ -35,6 +35,16 @@ sub showform ($$$$;@) { }); } + return $form; +} + +sub showform ($$$$;@) { + my $form=prepform(@_); + shift; + my $buttons=shift; + my $session=shift; + my $cgi=shift; + printheader($session); print misctemplate($form->title, $form->render(submit => $buttons), @_); } @@ -90,9 +100,10 @@ sub needsignin ($$) { } } -sub cgi_signin ($$) { +sub cgi_signin ($$;$) { my $q=shift; my $session=shift; + my $returnhtml=shift; decode_cgi_utf8($q); eval q{use CGI::FormBuilder}; @@ -112,9 +123,6 @@ sub cgi_signin ($$) { ); my $buttons=["Login"]; - if ($q->param("do") ne "signin" && !$form->submitted) { - $form->text(gettext("You need to log in first.")); - } $form->field(name => "do", type => "hidden", value => "signin", force => 1); @@ -129,6 +137,11 @@ sub cgi_signin ($$) { $form->validate; } + if ($returnhtml) { + $form=prepform($form, $buttons, $session, $q); + return $form->render(submit => $buttons); + } + showform($form, $buttons, $session, $q); } diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm index d75099ce9..e10e21f4d 100644 --- a/IkiWiki/Plugin/openid.pm +++ b/IkiWiki/Plugin/openid.pm @@ -62,17 +62,13 @@ sub openid_selector { $openid_error=shift; }); } - elsif ($q->param("do") eq "signin" && $real_cgi_signin) { - $real_cgi_signin->($q, $session); - exit; - } my $template=IkiWiki::template("openid-selector.tmpl"); $template->param( cgiurl => $config{cgiurl}, (defined $openid_error ? (openid_error => $openid_error) : ()), (defined $openid_url ? (openid_url => $openid_url) : ()), - ($real_cgi_signin ? (nonopenidurl => IkiWiki::cgiurl(do => "signin")) : ()), + ($real_cgi_signin ? (nonopenidform => $real_cgi_signin->($q, $session, 1)) : ()), ); IkiWiki::printheader($session); diff --git a/templates/openid-selector.tmpl b/templates/openid-selector.tmpl index 7e5ae9a01..b4d0e314f 100644 --- a/templates/openid-selector.tmpl +++ b/templates/openid-selector.tmpl @@ -2,21 +2,18 @@ - + + +
Select your account provider - -
+ +
+ +
+ +
+ +
diff --git a/underlays/openid-selector/ikiwiki/openid/openid-jquery.js b/underlays/openid-selector/ikiwiki/openid/openid-jquery.js index 59a59c084..bf14fd3d5 100644 --- a/underlays/openid-selector/ikiwiki/openid/openid-jquery.js +++ b/underlays/openid-selector/ikiwiki/openid/openid-jquery.js @@ -82,8 +82,9 @@ var openid = { input_id: null, provider_url: null, provider_id: null, + localsignin_id: null, - init: function(input_id, localloginurl) { + init: function(input_id, localsignin_id) { var openid_btns = $('#openid_btns'); @@ -105,13 +106,14 @@ var openid = { openid_btns.append(this.getBoxHTML(providers_small[id], 'small')); } } - if (localloginurl != "") { + if (localsignin_id != "") { + this.localsignin_id=localsignin_id; openid_btns.append( - '' + + 'class="localsignin openid_small_btn">' + '' + - ' Local Account' + + ' other' + '' ); } @@ -143,7 +145,20 @@ var openid = { }, /* Provider image click */ signin: function(box_id, onload) { - + + if (box_id == 'localsignin') { + this.highlight(box_id); + $('#openid_input_area').empty(); + $('#'+this.localsignin_id).show(); + this.setCookie(box_id); + return; + } + else { + if (this.localsignin_id) { + $('#'+this.localsignin_id).hide(); + } + } + var provider = providers[box_id]; if (! provider) { return;