From 7bb05f06fa763bf360b14045f79d491102a0f501 Mon Sep 17 00:00:00 2001 From: "gerv%gerv.net" <> Date: Mon, 29 Apr 2002 04:57:08 +0000 Subject: Bug 140103 - various templatisations or cleanups in CGI.pl. Patch by gerv; r=justdave, bbaetz. --- CGI.pl | 146 +++++++++++++++++------------------------------------------------ 1 file changed, 38 insertions(+), 108 deletions(-) (limited to 'CGI.pl') diff --git a/CGI.pl b/CGI.pl index c0e38c50a..979ffda0d 100644 --- a/CGI.pl +++ b/CGI.pl @@ -242,11 +242,9 @@ sub CheckFormFieldDefined (\%$) { $fieldname, # the fieldname to check ) = @_; - if ( !defined $formRef->{$fieldname} ) { - print "$fieldname was not defined; "; - print Param("browserbugmessage"); - PutFooter(); - exit 0; + if (!defined $formRef->{$fieldname}) { + ThrowCodeError("$fieldname was not defined; " . + Param("browserbugmessage")); } } @@ -489,22 +487,12 @@ sub CheckEmailSyntax { my ($addr) = (@_); my $match = Param('emailregexp'); if ($addr !~ /$match/ || $addr =~ /[\\\(\)<>&,;:"\[\] \t\r\n]/) { - print "Content-type: text/html\n\n"; - - # For security, escape HTML special characters. - $addr = html_quote($addr); - - PutHeader("Check e-mail syntax"); - print "The e-mail address you entered\n"; - print "($addr) didn't match our minimal\n"; - print "syntax checking for a legal email address.\n"; - print Param('emailregexpdesc') . "\n"; - print "It must also not contain any of these special characters: " . - "\\ ( ) & < > , ; : \" [ ] " . - "or any whitespace.\n"; - print "

Please click Back and try again.\n"; - PutFooter(); - exit; + ThrowUserError("The e-mail address you entered(" . + html_quote($addr) . ") didn't pass our syntax checking + for a legal email address. " . Param('emailregexpdesc') . + ' It must also not contain any of these special characters: + \ ( ) & < > , ; : " [ ], or any whitespace.', + "Check e-mail address syntax"); } } @@ -559,24 +547,17 @@ sub confirm_login { if ( defined $::FORM{"PleaseMailAPassword"} && !$userid ) { # Ensure the new login is valid if(!ValidateNewUser($enteredlogin)) { - DisplayError("Account Exists"); - exit; + ThrowUserError("That account already exists."); } my $password = InsertNewUser($enteredlogin, ""); - # There's a template for this - account_created.tmpl - but - # it's easier to wait to use it until templatisation has progressed - # further; we want to avoid sprinkling multiple copies of the - # template setup code everywhere - Gerv. - print "Content-Type: text/html\n\n"; - PutHeader("Account Created"); MailPassword($enteredlogin, $password); - print "The password for the e-mail address\n"; - print "$enteredlogin has been e-mailed to that address.\n"; - print "

When the e-mail arrives, you can click Back\n"; - print "and enter your password in the form there.\n"; - PutFooter(); - exit; + + $vars->{'login'} = $enteredlogin; + + print "Content-Type: text/html\n\n"; + $template->process("account/created.html.tmpl", $vars) + || ThrowTemplateError($template->error()); } # Otherwise, authenticate the user. @@ -755,14 +736,10 @@ Set-Cookie: Bugzilla_logincookie= ; path=$cookiepath; expires=Sun, 30-Jun-80 00: Content-type: text/html "; - PutHeader("Your account has been disabled"); - print $::disabledreason; - print "


\n"; - print "If you believe your account should be restored, please\n"; - print "send email to " . Param("maintainer") . " explaining\n"; - print "why.\n"; - PutFooter(); - exit(); + ThrowUserError($::disabledreason . "
" . + "If you believe your account should be restored, please " . + "send email to " . Param("maintainer") . " explaining why.", + "Your account has been disabled"); } print "Content-type: text/html\n\n"; PutHeader("Login"); @@ -871,72 +848,17 @@ Content-type: text/html return $::userid; } - sub PutHeader { - my ($title, $h1, $h2, $extra, $jscript) = (@_); - - if (!defined $h1) { - $h1 = $title; - } - if (!defined $h2) { - $h2 = ""; - } - if (!defined $extra) { - $extra = ""; - } - $jscript ||= ""; - - print qq| - - - -$title -| . Param("headerhtml") . qq| -$jscript - - -| . PerformSubsts(Param("bannerhtml"), undef) . qq| - - - - -
- - -
- - $h1 - -
-
  -$h2 -
- |; - - if (Param("shutdownhtml")) { - # If we are dealing with the params page, we want - # to ignore shutdownhtml - if ($0 !~ m:[\\/](do)?editparams.cgi$:) { - print "

\n"; - print Param("shutdownhtml"); - exit; - } - } + ($vars->{'title'}, $vars->{'h1'}, $vars->{'h2'}, + $vars->{'extra'}, $vars->{'jscript'}) = (@_); + + $::template->process("global/header.html.tmpl", $::vars) + || ThrowTemplateError($::template->error()); } -# Putfooter echoes footerhtml and by default prints closing tags -# -# param -# dontclose (boolean): avoid sending -# -# Example: -# Putfooter(); # normal close -# Putfooter(1); # don't send closing tags sub PutFooter { - my ( $dontclose ) = @_; - print PerformSubsts(Param("footerhtml")); - print "\n\n" if ( ! $dontclose ); - SyncAnyPendingShadowChanges(); + $::template->process("global/footer.html.tmpl", $::vars) + || ThrowTemplateError($::template->error()); } ############################################################################### @@ -1035,11 +957,19 @@ sub CheckIfVotedConfirmed { "(bug_id,who,bug_when,fieldid,removed,added) VALUES " . "($id,$who,now(),$fieldid,'0','1')"); } + AppendComment($id, DBID_to_name($who), "*** This bug has been confirmed by popular vote. ***"); - print "

Bug $id has been confirmed by votes.

\n"; - system("./processmail", $id); - print "
Go To BUG# $id
\n"; + + $vars->{'type'} = "votes"; + $vars->{'id'} = $id; + $vars->{'mail'} = ""; + open(PMAIL, "-|") or exec('./processmail', $id); + $vars->{'mail'} .= $_ while ; + close(PMAIL); + + $template->process("bug/process/results.html.tmpl", $vars) + || ThrowTemplateError($template->error()); } } -- cgit v1.2.3-24-g4f1b