summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/signinedit.pm
blob: 31160c02ffb581ad28da533e42737db8761295fe (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. section => "auth",
  17. },
  18. }
  19. sub canedit ($$$) {
  20. my $page=shift;
  21. my $cgi=shift;
  22. my $session=shift;
  23. # Have the user sign in, if they are not already. This is why the
  24. # hook runs last, so that any hooks that don't need the user to
  25. # signin can override this.
  26. if (! defined $session->param("name") ||
  27. ! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
  28. return "" unless exists $IkiWiki::hooks{auth};
  29. return sub { IkiWiki::needsignin($cgi, $session) };
  30. }
  31. else {
  32. return "";
  33. }
  34. }
  35. 1