pull request sent
[ikiwiki.git] / IkiWiki / UserInfo.pm
blob0bf100a959c934d23c8f73ac1f0962f856732a35
1 #!/usr/bin/perl
3 package IkiWiki;
5 use warnings;
6 use strict;
7 use Storable;
8 use IkiWiki;
10 sub userinfo_retrieve () {
11 my $userinfo=eval{ Storable::lock_retrieve("$config{wikistatedir}/userdb") };
12 return $userinfo;
15 sub userinfo_store ($) {
16 my $userinfo=shift;
18 my $newfile="$config{wikistatedir}/userdb.new";
19 my $oldmask=umask(077);
20 my $ret=Storable::lock_nstore($userinfo, $newfile);
21 umask($oldmask);
22 if (defined $ret && $ret) {
23 if (! rename($newfile, "$config{wikistatedir}/userdb")) {
24 unlink($newfile);
25 $ret=undef;
28 return $ret;
31 sub userinfo_get ($$) {
32 my $user=shift;
33 my $field=shift;
35 my $userinfo=userinfo_retrieve();
36 if (! defined $userinfo ||
37 ! exists $userinfo->{$user} || ! ref $userinfo->{$user} ||
38 ! exists $userinfo->{$user}->{$field}) {
39 return "";
41 return $userinfo->{$user}->{$field};
44 sub userinfo_set ($$$) {
45 my $user=shift;
46 my $field=shift;
47 my $value=shift;
49 my $userinfo=userinfo_retrieve();
50 if (! defined $userinfo ||
51 ! exists $userinfo->{$user} || ! ref $userinfo->{$user}) {
52 return "";
55 $userinfo->{$user}->{$field}=$value;
56 return userinfo_store($userinfo);
59 sub userinfo_setall ($$) {
60 my $user=shift;
61 my $info=shift;
63 my $userinfo=userinfo_retrieve();
64 if (! defined $userinfo) {
65 $userinfo={};
67 $userinfo->{$user}=$info;
68 return userinfo_store($userinfo);
71 sub is_admin ($) {
72 my $user_name=shift;
74 return grep { $_ eq $user_name } @{$config{adminuser}};