/[Frey]/trunk/lib/App/RoomReservation/Reservation.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/App/RoomReservation/Reservation.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1086 by dpavlin, Sun Jun 28 14:21:10 2009 UTC revision 1118 by dpavlin, Tue Jun 30 09:42:37 2009 UTC
# Line 1  Line 1 
1  package App::RoomReservation::Reservation;  package App::RoomReservation::Reservation;
2  use Moose;  use Moose;
3    
4  extends 'Frey';  use Moose::Util::TypeConstraints;
5  with 'Frey::Web';  use Regexp::Common qw[Email::Address];
6  #with 'Frey::Storage';  
7    subtype 'Email',
8            as 'Str',
9            where { /^$RE{Email}{Address}$/ },
10            message { "$_ is not valid e-mail" };
11    
12    extends 'App::RoomReservation';
13    
14    use lib 'lib';
15    use Frey::PPI;
16    
17  has ime => (  has ime => (
18          is => 'rw',          is => 'rw',
# Line 55  has mobitel => ( Line 64  has mobitel => (
64    
65  has email => (  has email => (
66          is => 'rw',          is => 'rw',
67          isa => 'Str',          isa => 'Email',
68          required => 1,          required => 1,
69  );  );
70    
71  has email_verify => (  has email_verify => (
72          is => 'rw',          is => 'rw',
73          isa => 'Str',          isa => 'Email',
74          required => 1,          required => 1,
75  );  );
76    
77  has _confirmed => (  has _confirmed => (
78          is => 'rw',          is => 'rw',
79          isa => 'Bool',          isa => 'Bool',
80          required => 1,  #       required => 1,
81          default => sub { 0 },          default => sub { 0 },
82  );  );
83    
84  sub as_markup {  sub BUILD {
85            my $self = shift;
86            die "e-mail not verified\n" unless $self->email eq $self->email_verify;
87    }
88    
89    my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;
90    warn "# cols = ",join(',', @cols), $/;
91    
92    sub token {
93            my $self = shift;
94            my $sth = $self->dbh->prepare(qq{
95                    select md5( id || email ) from reservation where email = ?
96            });
97            $sth->execute( $self->email );
98            $sth->fetchrow_array;
99    }
100    
101    sub create_as_markup {
102          my ($self) = @_;          my ($self) = @_;
103    
104          $self->ime;          my @vals;
105            my @p;
106    
107            map {
108                    push @vals, $self->$_;
109                    push @p, '?';
110            } @cols;
111    
112            my $n = $#cols + 1;
113    
114            my $sql
115                    = 'insert into reservation ('
116                    . join(',', @cols)
117                    . ') values ('
118                    . join(',', map { '?' } @cols )
119                    . ')'
120                    ;
121    
122            warn "sql: $sql\n";
123    
124            my $sth = $self->dbh->prepare( $sql );
125            $sth->execute( @vals );
126    
127            return
128                    $self->ime . ' ' . $self->prezime
129                    . qq| we have accepted your registration!|
130                    . qq|
131                            <div style="color:red">
132                            You have to confirm your e-mail address and registration
133                            by clicking on link which should be in your e-mail INBOX shortly
134                            </div>
135                    |
136                    . qq|<a href="/App::RoomReservation::Reservation::Confirmation/verify_as_markup?token=|
137                    . $self->token
138                    . qq|">verify</a>|
139                    . ' or '
140                    . qq|<a href="/App::RoomReservation::Reservation::Confirmation/cancel_as_markup?token=|
141                    . $self->token
142                    . qq|">cancel</a>|
143                    ;
144  }  }
145    
146    
147  1;  1;

Legend:
Removed from v.1086  
changed lines
  Added in v.1118

  ViewVC Help
Powered by ViewVC 1.1.26