X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/a7bd24b7b9c55e21ee998a751fd6771b9e71cb46..c7bdebaaf134729356852918b387071c92f85e72:/IkiWiki/Plugin/emailauth.pm?ds=sidebyside diff --git a/IkiWiki/Plugin/emailauth.pm b/IkiWiki/Plugin/emailauth.pm index 57100a2d7..6674fe3d6 100644 --- a/IkiWiki/Plugin/emailauth.pm +++ b/IkiWiki/Plugin/emailauth.pm @@ -8,7 +8,8 @@ use IkiWiki 3.00; sub import { hook(type => "getsetup", id => "emailauth", "call" => \&getsetup); - hook(type => "cgi", id => "cgi", "call" => \&cgi); + hook(type => "cgi", id => "emailauth", "call" => \&cgi); + hook(type => "formbuilder_setup", id => "emailauth", "call" => \&formbuilder_setup); IkiWiki::loadplugin("loginselector"); IkiWiki::Plugin::loginselector::register_login_plugin( "emailauth", @@ -25,6 +26,12 @@ sub getsetup () { rebuild => 0, section => "auth", }, + emailauth_sender => { + type => "string", + description => "email address to send emailauth mails as (default: adminemail)", + safe => 1, + rebuild => 0, + }, } sub email_setup ($$) { @@ -77,12 +84,16 @@ sub email_auth ($$$$) { eval q{use Mail::Sendmail}; error($@) if $@; + my $shorturl=$config{url}; + $shorturl=~s/^https?:\/\///i; + my $emailauth_sender=$config{emailauth_sender}; + $emailauth_sender=$config{adminemail} unless defined $emailauth_sender; sendmail( To => $email, From => "$config{wikiname} admin <". - (defined $config{adminemail} ? $config{adminemail} : "") + (defined $emailauth_sender ? $emailauth_sender : "") .">", - Subject => "$config{wikiname} login", + Subject => "$config{wikiname} login | $shorturl", Message => $template->output, ) or error(gettext("Failed to send mail")); @@ -111,6 +122,17 @@ sub cgi ($$) { } } +sub formbuilder_setup (@) { + my %params=@_; + my $form=$params{form}; + my $session=$params{session}; + + if ($form->title eq "preferences" && + IkiWiki::emailuser($session->param("name"))) { + $form->field(name => "email", disabled => 1); + } +} + # Generates the token that will be used in the authurl to log the user in. # This needs to be hard to guess, and relatively short. Generating a cgi # session id will make it as hard to guess as any cgi session.