--- trunk/lib/App/RoomReservation/Reservation.pm 2009/06/28 18:51:49 1095 +++ trunk/lib/App/RoomReservation/Reservation.pm 2009/06/30 15:10:55 1133 @@ -1,10 +1,16 @@ package App::RoomReservation::Reservation; use Moose; -extends 'Frey'; -with 'Frey::Web'; +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'; -use DBI; use lib 'lib'; use Frey::PPI; @@ -58,34 +64,54 @@ 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 }, ); -sub dsn { 'DBI:Pg:dbname=room-reservation' } +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 = shift; + my $sth = $self->dbh->prepare(qq{ + select md5( id || email ) from reservation where email = ? + }); + $sth->execute( $self->email ); + $sth->fetchrow_array; +} + sub create_as_markup { my ($self) = @_; - my $dbh = DBI->connect( $self->dsn, '', '', { RaiseError => 1 } ) || die $DBI::errstr; - $dbh->do( qq{ set client_encoding='utf-8' } ) if $self->dsn =~ m{pg}i; - my @vals; my @p; @@ -106,10 +132,30 @@ warn "sql: $sql\n"; - my $sth = $dbh->prepare( $sql ); + my $sth = $self->dbh->prepare( $sql ); $sth->execute( @vals ); - $sth->rows; + return + $self->ime . ' ' . $self->prezime + . qq| we have accepted your registration!| + . qq| +
+ You have to confirm your e-mail address and registration + 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;