summaryrefslogtreecommitdiff
path: root/ikiwiki
diff options
context:
space:
mode:
Diffstat (limited to 'ikiwiki')
-rwxr-xr-xikiwiki92
1 files changed, 87 insertions, 5 deletions
diff --git a/ikiwiki b/ikiwiki
index 54589ec2e..4b3bd488e 100755
--- a/ikiwiki
+++ b/ikiwiki
@@ -339,6 +339,7 @@ sub finalize ($$$) { #{{{
if (length $config{cgiurl}) {
$template->param(editurl => "$config{cgiurl}?do=edit&page=$page");
+ $template->param(prefsurl => "$config{cgiurl}?do=prefs");
if ($config{svn}) {
$template->param(recentchangesurl => "$config{cgiurl}?do=recentchanges");
}
@@ -883,7 +884,26 @@ sub userinfo_get ($$) { #{{{
return $userdata->{$user}->{$field};
} #}}}
-sub userinfo_set ($$) { #{{{
+sub userinfo_set ($$$) { #{{{
+ my $user=shift;
+ my $field=shift;
+ my $value=shift;
+
+ eval q{use Storable};
+ my $userdata=eval{ Storable::lock_retrieve("$config{srcdir}/.ikiwiki/userdb") };
+ if (! defined $userdata || ! ref $userdata ||
+ ! exists $userdata->{$user} || ! ref $userdata->{$user}) {
+ return "";
+ }
+
+ $userdata->{$user}->{$field}=$value;
+ my $oldmask=umask(077);
+ my $ret=Storable::lock_store($userdata, "$config{srcdir}/.ikiwiki/userdb");
+ umask($oldmask);
+ return $ret;
+} #}}}
+
+sub userinfo_setall ($$) { #{{{
my $user=shift;
my $info=shift;
@@ -905,7 +925,7 @@ sub cgi_signin ($$) { #{{{
eval q{use CGI::FormBuilder};
my $form = CGI::FormBuilder->new(
- title => "$config{wikiname} signin",
+ title => "signin",
fields => [qw(do page from name password confirm_password email)],
header => 1,
method => 'POST',
@@ -932,7 +952,7 @@ sub cgi_signin ($$) { #{{{
$form->field(name => "confirm_password", type => "password", required => 0);
$form->field(name => "email", required => 0);
if ($q->param("do") ne "signin") {
- $form->text("You need to log in before you can edit pages.");
+ $form->text("You need to log in first.");
}
if ($form->submitted) {
@@ -1010,7 +1030,7 @@ sub cgi_signin ($$) { #{{{
}
elsif ($form->submitted eq 'Register') {
my $user_name=$form->field('name');
- if (userinfo_set($user_name, {
+ if (userinfo_setall($user_name, {
'email' => $form->field('email'),
'password' => $form->field('password'),
'regdate' => time
@@ -1059,6 +1079,64 @@ sub cgi_signin ($$) { #{{{
}
} #}}}
+sub cgi_prefs ($$) { #{{{
+ my $q=shift;
+ my $session=shift;
+
+ eval q{use CGI::FormBuilder};
+ my $form = CGI::FormBuilder->new(
+ title => "preferences",
+ fields => [qw(do name password confirm_password email)],
+ header => 0,
+ method => 'POST',
+ validate => {
+ confirm_password => {
+ perl => q{eq $form->field("password")},
+ },
+ email => 'EMAIL',
+ },
+ required => 'NONE',
+ javascript => 0,
+ params => $q,
+ action => $q->request_uri,
+ template => (-e "$config{templatedir}/prefs.tmpl" ?
+ "$config{templatedir}/prefs.tmpl" : "")
+ );
+ my @buttons=("Save Preferences", "Logout", "Cancel");
+
+ my $user_name=$session->param("name");
+ $form->field(name => "do", type => "hidden");
+ $form->field(name => "name", disabled => 1,
+ value => $user_name, force => 1);
+ $form->field(name => "password", type => "password");
+ $form->field(name => "confirm_password", type => "password");
+
+ if (! $form->submitted) {
+ $form->field(name => "email", value => userinfo_get($user_name, "email"));
+ }
+
+ if ($form->submitted eq 'Logout') {
+ $session->delete();
+ print $q->redirect($config{url});
+ return;
+ }
+ elsif ($form->submitted eq 'Cancel') {
+ print $q->redirect($config{url});
+ return;
+ }
+ elsif ($form->submitted eq "Save Preferences" && $form->validate) {
+ foreach my $field (qw(password email)) {
+ if (length $form->field($field)) {
+ userinfo_set($user_name, $field, $form->field($field)) || error("failed to set $field");
+ }
+ }
+ $form->text("Preferences saved.");
+ }
+
+ print $session->header();
+ print misctemplate($form->title, $form->render(submit => \@buttons));
+} #}}}
+
sub cgi_editpage ($$) { #{{{
my $q=shift;
my $session=shift;
@@ -1268,7 +1346,8 @@ sub cgi () { #{{{
# Everything below this point needs the user to be signed in.
if ((! $config{anonok} && ! defined $session->param("name") ||
- ! userinfo_get($session->param("name"), "regdate")) || $do eq 'signin') {
+ ! defined $session->param("name") ||
+ ! userinfo_get($session->param("name"), "regdate")) || $do eq 'signin') {
cgi_signin($q, $session);
# Force session flush with safe umask.
@@ -1282,6 +1361,9 @@ sub cgi () { #{{{
if ($do eq 'create' || $do eq 'edit') {
cgi_editpage($q, $session);
}
+ elsif ($do eq 'prefs') {
+ cgi_prefs($q, $session);
+ }
else {
error("unknown do parameter");
}