aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2010-05-07 19:10:50 -0400
committerJoey Hess <joey@kitenet.net>2010-05-07 19:10:50 -0400
commit378c64776856ee1313c030375a921e8acb4ff1ef (patch)
tree46ac4d04807b83ddaa6d1026e616ef4626261237 /IkiWiki
parent76f6ff5f6b437534f8778abf225e2c4398262489 (diff)
downloadikiwiki-378c64776856ee1313c030375a921e8acb4ff1ef.tar
ikiwiki-378c64776856ee1313c030375a921e8acb4ff1ef.tar.gz
patch hidden field setting code
Fixes http://code.google.com/p/openid-selector/issues/detail?id=11#c3
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/openid.pm82
1 files changed, 69 insertions, 13 deletions
diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm
index 7b1a17831..0ad8697d8 100644
--- a/IkiWiki/Plugin/openid.pm
+++ b/IkiWiki/Plugin/openid.pm
@@ -7,6 +7,7 @@ use strict;
use IkiWiki 3.00;
sub import {
+ hook(type => "checkconfig", id => "openid", call => \&checkconfig);
hook(type => "getopt", id => "openid", call => \&getopt);
hook(type => "getsetup", id => "openid", call => \&getsetup);
hook(type => "auth", id => "openid", call => \&auth);
@@ -14,6 +15,18 @@ sub import {
call => \&formbuilder_setup, last => 1);
}
+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;
+ inject(name => "IkiWiki::cgi_signin", call => sub ($$) {
+ openid_selector($real_cgi_signin, @_);
+ });
+ }
+}
+
sub getopt () {
eval q{use Getopt::Long};
error($@) if $@;
@@ -37,6 +50,39 @@ sub getsetup () {
},
}
+sub openid_selector {
+ my $real_cgi_signin=shift;
+ my $q=shift;
+ my $session=shift;
+
+ my $openid_url=$q->param('openid_url');
+ my $openid_error;
+
+ if (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()) {
+ $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) : ()),
+ # TODO only if other auth methods are available
+ nonopenidurl => IkiWiki::cgiurl(do => "signin"),
+ loginlabel => loginlabel(),
+ );
+
+ IkiWiki::printheader($session);
+ print IkiWiki::misctemplate("signin", $template->output);
+ exit;
+}
+
sub formbuilder_setup (@) {
my %params=@_;
@@ -45,13 +91,7 @@ sub formbuilder_setup (@) {
my $cgi=$params{cgi};
if ($form->title eq "signin") {
- # Give up if module is unavailable to avoid
- # needing to depend on it.
- eval q{use Net::OpenID::Consumer};
- if ($@) {
- debug("unable to load Net::OpenID::Consumer, not enabling OpenID login ($@)");
- return;
- }
+ return unless load_openid_module();
# This avoids it displaying a redundant label for the
# OpenID fieldset.
@@ -59,7 +99,7 @@ sub formbuilder_setup (@) {
$form->field(
name => "openid_url",
- label => gettext("Log in with")." ".htmllink("", "", "ikiwiki/OpenID", noimageinline => 1),
+ label => loginlabel(),
fieldset => "OpenID",
size => 30,
comment => ($config{openidsignup} ? " | <a href=\"$config{openidsignup}\">".gettext("Get an OpenID")."</a>" : "")
@@ -72,7 +112,10 @@ sub formbuilder_setup (@) {
$form->field(
name => "openid_url",
validate => sub {
- validate($cgi, $session, shift, $form);
+ 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.
@@ -98,15 +141,14 @@ sub validate ($$$;$) {
my $q=shift;
my $session=shift;
my $openid_url=shift;
- my $form=shift;
+ my $errhandler=shift;
my $csr=getobj($q, $session);
my $claimed_identity = $csr->claimed_identity($openid_url);
if (! $claimed_identity) {
- if ($form) {
- # Put the error in the form and fail validation.
- $form->field(name => "openid_url", comment => $csr->err);
+ if ($errhandler) {
+ $errhandler->($csr->err);
return 0;
}
else {
@@ -230,4 +272,18 @@ sub getobj ($$) {
);
}
+sub load_openid_module {
+ # Give up if module is unavailable to avoid needing to depend on it.
+ eval q{use Net::OpenID::Consumer};
+ if ($@) {
+ debug("unable to load Net::OpenID::Consumer, not enabling OpenID login ($@)");
+ return;
+ }
+ return 1;
+}
+
+sub loginlabel {
+ return gettext("Log in with")." ".htmllink("", "", "ikiwiki/OpenID", noimageinline => 1);
+}
+
1