------------------------------------------------------------
Listing 4: edit-person.html

<!-- -*- mmm-classes: mason -*- -->
<HTML>

% # Make sure that we got all required name-value pairs
% unless ($email and $new_first) {

    <Head>
        <Title>Missing information!</Title>
    </Head>

    <Body>
    <H1>Missing information!</H1>

    <P>Sorry, but you need to provide us with the person's e-mail
    address and their new first name.</P>

% # Make sure that the e-mail address looks somewhat valid
% } elsif ($email !~ /[.\w]+@\w+\.\w{2,3}/) {

    <Head>             
        <Title>Bad e-mail address!</Title>
    </Head>

    <Body>
        <H1>Bad e-mail address!</H1>

    <P>Sorry, but the provided e-mail address doesn't look legal.</P>

% # If we made it this far, use $email to choose the person, then
% # change the first name with the API

% } else {

<%perl>
my $set_person_successfully =
    $people->set_current_person_by_email($email);
</%perl>

% if ($set_person_successfully) {

<%perl>
my $updated_name_successfully =
    $people->update_first_name($new_first);
</%perl>

% if ($updated_name_successfully) {

    <Head>
    <Title>Success!</Title>
    </Head>

    <Body>
    <H1>Success!</H1>

    <P>You successfully changed the first name.</P>

% } else {

    <Head>
    <Title>Error!</Title>
    </Head>

    <Body>
    <H1>Error!</H1> 
    
    <P>There was an error trying to set the name for "<% $email %>" to
    "<% $new_first %>".</P>

% }


% } else {

    <Head>
    <Title>Error!</Title>
    </Head>

    <Body>
    <H1>Error!</H1>

    <P>There was an error trying to set the current person based on
    the e-mail address "<% $email %>".</P>

% }

% } 

</Body>
</HTML>

<%init>
use People;
my $people = new People;
</%init>

<%args>
$email
$new_first
</%args>                                                        
