Index: web/Makefile.PL
===================================================================
--- web/Makefile.PL	(revision 460)
+++ web/Makefile.PL	(revision 461)
@@ -31,4 +31,5 @@
 requires 'Catalyst::View::JSON' => '0';
 requires 'Catalyst::View::GD' => '0';
+requires 'Catalyst::View::Email' => '0';
 requires 'Catalyst::Model::DBIC::Schema';
 requires 'Catalyst::Authentication::Store::DBIx::Class';
Index: web/Sophie.spec.in
===================================================================
--- web/Sophie.spec.in	(revision 460)
+++ web/Sophie.spec.in	(revision 461)
@@ -54,4 +54,5 @@
 Requires: perl(Catalyst::View::JSON)
 Requires: perl(Catalyst::View::GD)
+Requires: perl(Catalyst::View::Email)
 Requires: perl(Catalyst::Plugin::Compress::Zlib)
 Requires: perl-Catalyst-Plugin-Server
Index: web/lib/Sophie.pm
===================================================================
--- web/lib/Sophie.pm	(revision 460)
+++ web/lib/Sophie.pm	(revision 461)
@@ -79,4 +79,16 @@
         },
     },
+    'View::Email' => {
+        default => {
+            charset => 'utf-8',
+            content_type => 'text/plain',
+        },
+        sender => {
+            mailer => 'SMTP',
+            mailer_args => {
+                host => 'localhost',
+            },
+        },
+    }
 );
 
Index: web/lib/Sophie/Controller/Login.pm
===================================================================
--- web/lib/Sophie/Controller/Login.pm	(revision 460)
+++ web/lib/Sophie/Controller/Login.pm	(revision 461)
@@ -56,10 +56,14 @@
     my ($self, $c, $mail) = @_;
 
-    my $valid_code = join('', map { printf("%02x", rand(256)) } (0 .. 15));
+    my $valid_code = join('', map { sprintf("%02x", rand(256)) } (0 .. 15));
 
     $c->model('Base::AccountRequest')->create({
             mail => $mail,
             valid_code => $valid_code,
+            ip_address => $c->req->address,
     });
+    $c->model('Base')->storage->dbh->commit;
+
+    return $valid_code;
 }
 
@@ -67,20 +71,28 @@
     my ($self, $c) = @_;
 
-    warn $c->req->param('valid');
-    warn $c->session->{valid_create_user};
     if ((my $valid = $c->req->param('valid')) && $c->req->param('username')) {
+       # create a login request
+       my $valid_code = $c->forward('create_request', [ $c->req->param('username') ],);
+
        if ($valid == $c->session->{valid_create_user}) {
-           my $res = $c->forward('/admin/create_user',
-               [
-                   $c->req->param('username'),
-                   $c->req->param('password'),
-               ]
-            );
-            if ($res) {
-               $c->res->redirect($c->uri_for('/login',
-                   { username => $c->req->param('username') }
-               ));
-           }
-       }
+           $c->stash->{email} = {
+               header => [
+                   to      => $c->req->param('username'),
+                   from    => 'sophie@zarb.org',
+                   subject => 'Sophie.zarb.org confirm request',
+               ],
+               body    => "
+Someone, hopefully you, request an account on Sophe web site.
+
+To complete your subscription follow the link bellow:
+
+" . $c->uri_for('/login/confirm', { id => $valid_code }) . "
+
+If this is an error, simply ignore this mail.
+
+",
+           };
+           $c->forward( $c->view('Email') );
+        }
     }
     my $aa = (0 .. 9)[rand(9)];
@@ -88,4 +100,36 @@
     $c->stash->{valid} = "$aa + $bb";
     $c->session->{valid_create_user} = $aa + $bb;
+}
+
+sub confirm :Local {
+    my ($self, $c) = @_;
+
+    my $reqid = $c->req->param('id');
+
+    my $request = $c->model('Base::AccountRequest')->find(
+        {
+            valid_code => $reqid,
+        });
+    if (!$request) {
+        # ERR
+    }
+    $c->stash->{email} = $request->mail;
+
+    if ($c->req->param('password')) {
+       my $res = $c->forward('/admin/create_user',
+           [
+               $request->mail,
+               $c->req->param('password'),
+           ]
+        );
+        if ($res) {
+           $request->delete;
+           $c->model('Base')->storage->dbh->commit;
+           # TODO authenticate user directly
+           $c->res->redirect($c->uri_for('/login',
+               { username => $request->mail }
+           ));
+       }
+    }
 }
 
Index: web/lib/Sophie/View/Email.pm
===================================================================
--- web/lib/Sophie/View/Email.pm	(revision 461)
+++ web/lib/Sophie/View/Email.pm	(revision 461)
@@ -0,0 +1,33 @@
+package Sophie::View::Email;
+
+use strict;
+use base 'Catalyst::View::Email';
+
+__PACKAGE__->config(
+    stash_key => 'email'
+);
+
+=head1 NAME
+
+Sophie::View::Email - Email View for Sophie
+
+=head1 DESCRIPTION
+
+View for sending email from Sophie. 
+
+=head1 AUTHOR
+
+olivier
+
+=head1 SEE ALSO
+
+L<Sophie>
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
Index: web/root/templates/html/login/confirm.html
===================================================================
--- web/root/templates/html/login/confirm.html	(revision 461)
+++ web/root/templates/html/login/confirm.html	(revision 461)
@@ -0,0 +1,12 @@
+<!-- $Id$ -->
+
+<div id="sophie_create_user" class="sophie_auth">
+<p>Create a new user:</p>
+<form action="[% c.uri_for('/login/confirm') %]">
+    [% email | html %]<br>
+    <input type="hidden" value="[% c.req.param('id') %]" name="id">
+    <label for="password">Choose a password:</label> <input id="password" type="password" name="password"><br>
+    <label for="password">Confirm Password:</label> <input id="password" type="password" name="password"><br>
+    <input type="submit"> 
+</form>
+</div>
Index: web/root/templates/html/login/create.tt
===================================================================
--- web/root/templates/html/login/create.tt	(revision 460)
+++ web/root/templates/html/login/create.tt	(revision 461)
@@ -6,5 +6,4 @@
     <label for="username">Email:</label>
         <input type="text" id="username" name="username" value="[% c.req.param('username') %]"><br>
-    <label for="password">Password:</label> <input id="password" type="password" name="password"><br>
     <p>Please enter the result of:</p>
     <label for="valid">[% valid | html %]:</label>
Index: web/t/view_Email.t
===================================================================
--- web/t/view_Email.t	(revision 461)
+++ web/t/view_Email.t	(revision 461)
@@ -0,0 +1,8 @@
+use strict;
+use warnings;
+use Test::More;
+
+
+BEGIN { use_ok 'Sophie::View::Email' }
+
+done_testing();
