+sub cgi_recentchanges () { #{{{
+ my $q=shift;
+
+ my $template=HTML::Template->new(
+ filename => "$templatedir/recentchanges.tmpl");
+ $template->param(
+ title => "RecentChanges",
+ indexlink => $url,
+ wikiname => $wikiname,
+ changelog => [rcs_recentchanges(100)],
+ );
+ return $template->output;
+} #}}}
+
+sub cgi_signin ($$) { #{{{
+ my $q=shift;
+ my $session=shift;
+
+ eval q{use CGI::FormBuilder};
+ my $form = CGI::FormBuilder->new(
+ title => "$wikiname signin",
+ fields => [qw(do page name password confirm_password email)],
+ header => 1,
+ method => 'POST',
+ validate => {
+ name => '/^\w+$/',
+ confirm_password => {
+ perl => q{eq $form->field("password")},
+ },
+ email => 'EMAIL',
+ },
+ required => 'NONE',
+ javascript => 0,
+ params => $q,
+ action => $q->request_uri,
+ );
+
+ $form->sessionid($session->id);
+ $form->field(name => "name", required => 0);
+ $form->field(name => "do", type => "hidden");
+ $form->field(name => "page", type => "hidden");
+ $form->field(name => "password", type => "password", required => 0);
+ $form->field(name => "confirm_password", type => "password", required => 0);
+ $form->field(name => "email", required => 0);
+ if ($session->param("name")) {
+ $form->field(name => "name", value => $session->param("name"));
+ }
+ if ($q->param("do") ne "signin") {
+ $form->text("You need to log in before you can edit pages.");
+ }
+
+ if ($form->submitted) {
+ # Set required fields based on how form was submitted.
+ my %required=(
+ "Login" => [qw(name password)],
+ "Register" => [qw(name password confirm_password email)],
+ "Mail Password" => [qw(name)],
+ );
+ foreach my $opt (@{$required{$form->submitted}}) {
+ $form->field(name => $opt, required => 1);
+ }
+
+ # Validate password differently depending on how form was
+ # submitted.
+ if ($form->submitted eq 'Login') {
+ $form->field(
+ name => "password",
+ validate => sub {
+ # TODO get real user password
+ shift eq "foo";
+ },
+ );
+ }
+ else {
+ $form->field(name => "password", validate => 'VALUE');
+ }
+ }
+ else {
+ # Comments only shown first time.
+ $form->field(name => "name", comment => "use FirstnameLastName");
+ $form->field(name => "confirm_password", comment => "(only needed");
+ $form->field(name => "email", comment => "for registration)");
+ }
+
+ if ($form->submitted && $form->validate) {
+ if ($form->submitted eq 'Login') {
+ $session->param("name", $form->field("name"));
+ if (defined $form->field("do")) {
+ $q->redirect(
+ "$cgiurl?do=".$form->field("do").
+ "&page=".$form->field("page"));
+ }
+ else {
+ $q->redirect($url);
+ }
+ }
+ elsif ($form->submitted eq 'Register') {
+ # TODO: save registration info
+ $form->field(name => "confirm_password", type => "hidden");
+ $form->field(name => "email", type => "hidden");
+ $form->text("Registration successful. Now you can Login.");
+ print $form->render(submit => ["Login"]);;
+ }
+ elsif ($form->submitted eq 'Mail Password') {
+ # TODO mail password
+ $form->text("Your password has been emailed to you.");
+ print $form->render(submit => ["Login", "Register", "Mail Password"]);;
+ }
+ }
+ else {
+ print $form->render(submit => ["Login", "Register", "Mail Password"]);;
+ }
+} #}}}
+
+sub cgi () { #{{{