summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-03-21 02:38:17 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-03-21 02:38:17 +0000
commit5fe80a63716bd47a501a5fdd32f25d0030e4048f (patch)
tree566c26cce5f19dc881a361d63a889ae3dc55875a
parentb7d3a12c5c8d2c41ebba091884a68e009344c3e5 (diff)
prefs page implemented
-rw-r--r--doc/templates.mdwn18
-rw-r--r--doc/todo.mdwn4
-rwxr-xr-xikiwiki92
-rw-r--r--templates/page.tmpl4
4 files changed, 102 insertions, 16 deletions
diff --git a/doc/templates.mdwn b/doc/templates.mdwn
index 6d914ef5a..3521ab012 100644
--- a/doc/templates.mdwn
+++ b/doc/templates.mdwn
@@ -2,6 +2,8 @@ ikiwiki uses the HTML::Template module as its template engine. This
supports things like conditionals and loops in templates and is pretty easy
to learn.
+I aim to keep almost all html out of ikiwiki and in the templates.
+
It ships with some basic templates which can be customised:
* `templates/page.tmpl` - Used for displaying all regular wiki pages.
@@ -12,15 +14,17 @@ It ships with some basic templates which can be customised:
* `templates/passwordmail.tmpl` - Not a html template, this is used to
generate the mail with the user's password in it.
-If you like, you can add this to further customise it:
+If you like, you can add these to further customise it:
* `templates/signin.tmpl` - If it exists, it is used for customising the
layout of the SignIn form and all assciated forms. The misc.tmpl is
wrapped around this, so it should only be a template for the form.
+* `templates/prefs.tmpl` - If it exists, it is used for customising the
+ layout of the Prefs form and all assciated forms. The misc.tmpl is
+ wrapped around this, so it should only be a template for the form.
- Note that the SignIn form is implemented using CGI::FormBuilder, which
- interfaces to HTML::Template, so not all of it can be customised with
- templates, although most of it can, by creating this template. Without
- the template, CGI::FormBuilder creates the page body by itself.
-
-I aim to keep almost all html out of ikiwiki and in the templates.
+Note that the SignIn and Prefs forms are implemented using
+CGI::FormBuilder, which interfaces to HTML::Template, so not all of it can
+be customised with templates, although most of it can, by creating these
+templates. Without the templates, CGI::FormBuilder creates the page bodies
+by itself.
diff --git a/doc/todo.mdwn b/doc/todo.mdwn
index 00fcc0ce3..d8c5a5b8b 100644
--- a/doc/todo.mdwn
+++ b/doc/todo.mdwn
@@ -110,10 +110,6 @@ Some wikis will need the abiity to lock a page, or the whole wiki, so that only
Probably it's ok if locking is only supported for web commits.
-## User settings page
-
-A cgi page to allow a user to log out and to edit their prefs, including password, email, and anything we add later (subscriptions, etc).
-
## Logo
ikiwiki needs a logo. I'm thinking something simple like the word "ikiwiki" with the first "k" backwards; drawn to show that it's "wiki" reflected.
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");
}
diff --git a/templates/page.tmpl b/templates/page.tmpl
index 141d86a10..1e484056e 100644
--- a/templates/page.tmpl
+++ b/templates/page.tmpl
@@ -21,6 +21,10 @@
<a href="<TMPL_VAR HISTORYURL>">History</a>&nbsp;
</TMPL_IF>
+<TMPL_IF NAME="PREFSURL">
+<a href="<TMPL_VAR PREFSURL>">Preferences</a>&nbsp;
+</TMPL_IF>
+
<TMPL_VAR DISCUSSIONLINK><br>
<hr>