X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/1fb1d6c1830a3d80bd6940bc2b24ca4f673e1bed..68a9345b5c17fe007373c567666a25e6dc5544fa:/IkiWiki/CGI.pm?ds=sidebyside diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 1522feb1e..65a1d7fa0 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -20,7 +20,7 @@ sub printheader ($) { #{{{ } } #}}} - + sub showform ($$$$) { #{{{ my $form=shift; my $buttons=shift; @@ -60,12 +60,18 @@ sub check_canedit ($$$;$) { #{{{ run_hooks(canedit => sub { return if defined $canedit; my $ret=shift->($page, $q, $session); - if (defined $ret && $ret eq "") { - $canedit=1; - } - elsif (defined $ret) { - $canedit=0; - error($ret) unless $nonfatal; + if (defined $ret) { + if ($ret eq "") { + $canedit=1; + } + elsif (ref $ret eq 'CODE') { + $ret->() unless $nonfatal; + $canedit=0; + } + elsif (defined $ret) { + error($ret) unless $nonfatal; + $canedit=0; + } } }); return $canedit; @@ -133,9 +139,7 @@ sub needsignin ($$) { #{{{ if (! defined $session->param("name") || ! userinfo_get($session->param("name"), "regdate")) { - if (! defined $session->param("postsignin")) { - $session->param(postsignin => $ENV{QUERY_STRING}); - } + $session->param(postsignin => $ENV{QUERY_STRING}); cgi_signin($q, $session); cgi_savesession($session); exit; @@ -195,9 +199,7 @@ sub cgi_postsignin ($$) { #{{{ exit; } else { - # This can occur, for example, if a user went to the signin - # url via a bookmark. - redirect($q, $config{url}); + error(gettext("login failed, perhaps you need to turn on cookies?")); } } #}}} @@ -273,7 +275,7 @@ sub cgi_prefs ($$) { #{{{ } elsif ($form->submitted eq 'Save Preferences' && $form->validate) { foreach my $field (qw(email subscriptions)) { - if (defined $form->field($field) && length $form->field($field)) { + if (defined $form->field($field)) { userinfo_set($user_name, $field, $form->field($field)) || error("failed to set $field"); } @@ -710,17 +712,14 @@ sub cgi (;$$) { #{{{ cgi_signin($q, $session); cgi_savesession($session); } - elsif (defined $session->param("postsignin")) { - cgi_postsignin($q, $session); - } elsif ($do eq 'prefs') { cgi_prefs($q, $session); } elsif ($do eq 'create' || $do eq 'edit') { cgi_editpage($q, $session); } - elsif ($do eq 'postsignin') { - error(gettext("login failed, perhaps you need to turn on cookies?")); + elsif (defined $session->param("postsignin") || $do eq 'postsignin') { + cgi_postsignin($q, $session); } else { error("unknown do parameter");