prefs page implemented
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Tue, 21 Mar 2006 02:38:17 +0000 (02:38 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Tue, 21 Mar 2006 02:38:17 +0000 (02:38 +0000)
doc/templates.mdwn
doc/todo.mdwn
ikiwiki
templates/page.tmpl

index 6d914ef5a8170de15a0389beb26f9628fdb03b2c..3521ab012eeb9e0be5c1d8fb9d6f1b9942dce908 100644 (file)
@@ -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.
 
 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.
 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.
 
 * `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/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.
index 00fcc0ce3885acba56238fcf8a092e3b472fbf43..d8c5a5b8b549b66f51cb4aa4b047f6e9c6bd0bbc 100644 (file)
@@ -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.
 
 
 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.
 ## 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 54589ec2e05cc24252c59783cab9e7a3503e71b2..4b3bd488eac4715ead8a3e415da2fb1b81694df5 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -339,6 +339,7 @@ sub finalize ($$$) { #{{{
        
        if (length $config{cgiurl}) {
                $template->param(editurl => "$config{cgiurl}?do=edit&page=$page");
        
        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");
                }
                if ($config{svn}) {
                        $template->param(recentchangesurl => "$config{cgiurl}?do=recentchanges");
                }
@@ -883,7 +884,26 @@ sub userinfo_get ($$) { #{{{
        return $userdata->{$user}->{$field};
 } #}}}
 
        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;
        
        my $user=shift;
        my $info=shift;
        
@@ -905,7 +925,7 @@ sub cgi_signin ($$) { #{{{
 
        eval q{use CGI::FormBuilder};
        my $form = CGI::FormBuilder->new(
 
        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',
                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->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) {
        }
        
        if ($form->submitted) {
@@ -1010,7 +1030,7 @@ sub cgi_signin ($$) { #{{{
                }
                elsif ($form->submitted eq 'Register') {
                        my $user_name=$form->field('name');
                }
                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
                                           '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;
 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") ||
        
        # 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.
                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);
        }
        if ($do eq 'create' || $do eq 'edit') {
                cgi_editpage($q, $session);
        }
+       elsif ($do eq 'prefs') {
+               cgi_prefs($q, $session);
+       }
        else {
                error("unknown do parameter");
        }
        else {
                error("unknown do parameter");
        }
index 141d86a10313227b472e152a80154ca33dbbf9a5..1e484056ee6f4f68bf60136df84cee27bf26b0f9 100644 (file)
 <a href="<TMPL_VAR HISTORYURL>">History</a>&nbsp;
 </TMPL_IF>
 
 <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>
 <TMPL_VAR DISCUSSIONLINK><br>
 
 <hr>