<!yatt:args nx>
<yatt:envelope guest_ok>
  <:yatt:title>Registration Form</:yatt:title>
<form method="POST">
  <table>
    <tr>
      <th>User ID:</th>
      <td><input type="text" name=".login" size="15"></td>
    </tr>
    <tr>
      <th>Password:</th>
      <td><input type="password" name=".password" size="15"></td>
    </tr>
    <tr>
      <th>(Retype password):</th>
      <td><input type="password" name=".password2" size="15"></td>
    </tr>
    <tr>
      <th>Email:</th>
      <td><input type="text" name=".email" size="30"></td>
    </tr>
    <tr>
      <td colspan="2">
        <input type="hidden" name=".nx" value="&yatt:nx;"/>
        <input type="submit" name="!register"/>
      </td>
    </tr>
  </table>
</form>
</yatt:envelope>

<!yatt:action register>
my ($this, $con) = @_;

my $login = $con->param_type
  ('.login', qr{^\w{4,12}$ }x
   , 'Login name is alphabet + number only, length 4 to 12');

if ($this->YATT->is_user($login)) {
  die "Login name $login is already used, please choose another name";
}

my $pass1 = $con->param('.password')
  or die "Password is empty";
my $pass2 = $con->param('.password2')
  or die "Password2 is empty";

unless ($pass1 eq $pass2) {
  die "Password mismatch!";
}

my $email = $con->param_type
  ('.email', qr{^[\w\.\-]+\@[\w\.\-]+$ }x
   , 'Email should be written like: username@domain.name');

my ($user, $token) = $this->YATT->add_user($login, $pass1, $email);

# XXX: query 追加の API も用意すべきでは?
my $url = $con->mkurl(undef, ['!confirm' => 1, token => $token]);

my $back = $con->param('.nx') || 'index.yatt';

if ($this->YATT->sendmail($con, $this, email => $email, $url)) {
  $this->render_sent($con, $back);
} else {
  die "Can't send email!";
}

<!yatt:widget email to url=html>
From: webmaster@localhost.localdomain
To: &yatt:to;
Subject: Confirm
Content-type: text/plain; charset="utf-8"

ご登録、ありがとうございます。登録を承認する場合は
下のリンクをクリックしてください。

Thank you for registration. To confirm your registration,
please click following link:

&yatt:url;

心当たりの無い方は、このメールは破棄してください。

If you have received this mail without having requested it,
please dispose this mail.

<!yatt:widget sent back>
<yatt:envelope guest_ok>
  <h2>Confirmation Email is Sent to you.</h2>
  <a href="&yatt:back;">back</a>
</yatt:envelope>

<!yatt:action confirm token>
;
unless (defined $token and $token ne '') {
  die $CON->error_with_status(400, 'Token is empty');
}

my $user = $this->entity_resultset('user')->find({confirm_token => $token})
  or die "Invalid token!";

$user->confirm_token(undef);
$user->update;

$this->entity_set_logged_in($user->login);

$this->render_success($CON, $user);

<!yatt:widget success user>
<yatt:envelope>
  <h2>Welcome! Your registration is successfully completed.</h2>
  <a href="./">Top</a>
</yatt:envelope>
