summaryrefslogtreecommitdiff
path: root/IkiWiki/UserInfo.pm
blob: f4e261563d3ef625be6e776014a93eaf7fd691f5 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Storable;
  5. package IkiWiki;
  6. sub userinfo_retrieve () { #{{{
  7. my $userinfo=eval{ Storable::lock_retrieve("$config{wikistatedir}/userdb") };
  8. return $userinfo;
  9. } #}}}
  10. sub userinfo_store ($) { #{{{
  11. my $userinfo=shift;
  12. my $oldmask=umask(077);
  13. my $ret=Storable::lock_store($userinfo, "$config{wikistatedir}/userdb");
  14. umask($oldmask);
  15. return $ret;
  16. } #}}}
  17. sub userinfo_get ($$) { #{{{
  18. my $user=shift;
  19. my $field=shift;
  20. my $userinfo=userinfo_retrieve();
  21. if (! defined $userinfo ||
  22. ! exists $userinfo->{$user} || ! ref $userinfo->{$user} ||
  23. ! exists $userinfo->{$user}->{$field}) {
  24. return "";
  25. }
  26. return $userinfo->{$user}->{$field};
  27. } #}}}
  28. sub userinfo_set ($$$) { #{{{
  29. my $user=shift;
  30. my $field=shift;
  31. my $value=shift;
  32. my $userinfo=userinfo_retrieve();
  33. if (! defined $userinfo ||
  34. ! exists $userinfo->{$user} || ! ref $userinfo->{$user}) {
  35. return "";
  36. }
  37. $userinfo->{$user}->{$field}=$value;
  38. return userinfo_store($userinfo);
  39. } #}}}
  40. sub userinfo_setall ($$) { #{{{
  41. my $user=shift;
  42. my $info=shift;
  43. my $userinfo=userinfo_retrieve();
  44. if (! defined $userinfo) {
  45. $userinfo={};
  46. }
  47. $userinfo->{$user}=$info;
  48. return userinfo_store($userinfo);
  49. } #}}}
  50. sub is_admin ($) { #{{{
  51. my $user_name=shift;
  52. return grep { $_ eq $user_name } @{$config{adminuser}};
  53. } #}}}
  54. sub page_subscribers (@) { #{{{
  55. my @ret;
  56. my $userinfo=userinfo_retrieve();
  57. foreach my $user (keys %{$userinfo}) {
  58. if (exists $user->{subscriptions} &&
  59. length $user->{subscriptions} &&
  60. exists $user->{email} &&
  61. length $user->{email} &&
  62. grep { globmatch($_, $user->{subscriptions}) } @_) {
  63. push @ret, $user->{email};
  64. }
  65. }
  66. return @ret;
  67. } #}}}
  68. 1