--- trunk/lib/App/RoomReservation/Reservation.pm 2009/06/28 22:14:22 1098
+++ trunk/lib/App/RoomReservation/Reservation.pm 2009/06/30 15:59:41 1134
@@ -1,8 +1,18 @@
package App::RoomReservation::Reservation;
use Moose;
+use Moose::Util::TypeConstraints;
+use Regexp::Common qw[Email::Address];
+
+subtype 'Email',
+ as 'Str',
+ where { /^$RE{Email}{Address}$/ },
+ message { "$_ is not valid e-mail" };
+
extends 'App::RoomReservation';
+with 'App::RoomReservation::Email';
+
use lib 'lib';
use Frey::PPI;
@@ -56,28 +66,43 @@
has email => (
is => 'rw',
- isa => 'Str',
+ isa => 'Email',
required => 1,
);
has email_verify => (
is => 'rw',
- isa => 'Str',
+ isa => 'Email',
required => 1,
);
has _confirmed => (
is => 'rw',
isa => 'Bool',
- required => 1,
+# required => 1,
default => sub { 0 },
);
+has _seat_number => (
+ is => 'rw',
+ isa => 'Int',
+);
+
+sub BUILD {
+ my $self = shift;
+ die "e-mail not verified\n" unless $self->email eq $self->email_verify;
+ my $sth = $self->dbh->prepare(qq{
+ select count(*) from reservation where email = ?
+ });
+ $sth->execute( $self->email );
+ my ($registred) = $sth->fetchrow_array;
+ die "e-mail address ", $self->email, " allready registred\n" if $registred;
+}
+
my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;
warn "# cols = ",join(',', @cols), $/;
sub token {
- my ( $self ) = @_;
my $self = shift;
my $sth = $self->dbh->prepare(qq{
select md5( id || email ) from reservation where email = ?
@@ -112,6 +137,16 @@
my $sth = $self->dbh->prepare( $sql );
$sth->execute( @vals );
+ my $token = $self->token;
+ $self->send( $self->email,
+ 'Confirm your reservation for lecture', <<__EMAIL__
+Please click following link to confirm your reservation for lecture
+and get seat assigned to you.
+
+http://FREY_HOSTNAME/App::RoomReservation::Confirmation/verify_as_markup?token=$token
+__EMAIL__
+ );
+
return
$self->ime . ' ' . $self->prezime
. qq| we have accepted your registration!|
@@ -121,15 +156,11 @@
by clicking on link which should be in your e-mail INBOX shortly
|
- . qq|verify|
- . ' or '
- . qq|cancel|
;
}
+__PACKAGE__->meta->make_immutable;
+no Moose;
+no Moose::Util::TypeConstraints;
1;