summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/signinedit.pm
blob: 8b44a68f725230118d7fe71619793a1bac3199b2 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::signinedit;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.00;
  6. sub import {
  7. hook(type => "getsetup", id => "signinedit", call => \&getsetup);
  8. hook(type => "canedit", id => "signinedit", call => \&canedit,
  9. last => 1);
  10. }
  11. sub getsetup () {
  12. return
  13. plugin => {
  14. safe => 1,
  15. rebuild => 0,
  16. },
  17. }
  18. sub canedit ($$$) {
  19. my $page=shift;
  20. my $cgi=shift;
  21. my $session=shift;
  22. # Have the user sign in, if they are not already. This is why the
  23. # hook runs last, so that any hooks that don't need the user to
  24. # signin can override this.
  25. if (! defined $session->param("name") ||
  26. ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
  27. return "" unless exists $IkiWiki::hooks{auth};
  28. return sub { IkiWiki::needsignin($cgi, $session) };
  29. }
  30. else {
  31. return "";
  32. }
  33. }
  34. 1