use warnings;
use strict;
-use IkiWiki;
+use IkiWiki 2.00;
sub import { #{{{
hook(type => "getopt", id => "openid", call => \&getopt);
my $form=$params{form};
my $session=$params{session};
my $cgi=$params{cgi};
+
+ # 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;
+ }
if ($form->title eq "signin") {
+ # This avoids it displaying a redundant label for the
+ # OpenID fieldset.
+ $form->fieldsets("OpenID");
+
$form->field(
name => "openid_url",
- label => "OpenID",
+ label => gettext("Log in with")." ".htmllink("", "", "ikiwiki/OpenID", noimageinline => 1),
+ fieldset => "OpenID",
size => 30,
- comment => '('.
- htmllink("", "", "OpenID", 1, 0, "What's this?")
- .($config{openidsignup} ? " | <a href=\"$config{openidsignup}\">Get an OpenID</a>" : "")
- .')'
+ comment => ($config{openidsignup} ? " | <a href=\"$config{openidsignup}\">".gettext("Get an OpenID")."</a>" : "")
);
# Handle submission of an OpenID as validation.
}
elsif ($form->title eq "preferences") {
if (! defined $form->field(name => "name")) {
- $form->field(name => "OpenID", disabled => 1, value =>
- $session->param("name"), size => 30, force => 1);
+ $form->field(name => "OpenID", disabled => 1,
+ value => $session->param("name"),
+ size => 50, force => 1,
+ fieldset => "login");
}
}
}
# Store the secret in the session.
my $secret=$session->param("openid_secret");
if (! defined $secret) {
- $secret=$session->param(openid_secret => time);
+ $secret=rand;
+ $session->param(openid_secret => $secret);
}
return Net::OpenID::Consumer->new(
ua => $ua,
args => $q,
- consumer_secret => $secret,
+ consumer_secret => sub { return shift()+$secret },
required_root => $config{cgiurl},
);
} #}}}