/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1118 - (hide annotations)
Tue Jun 30 09:42:37 2009 UTC (14 years, 9 months ago) by dpavlin
File size: 2351 byte(s)
added Email type (which now renders as textarea istead of input type=text, sigh!)
1 dpavlin 1086 package App::RoomReservation::Reservation;
2     use Moose;
3    
4 dpavlin 1118 use Moose::Util::TypeConstraints;
5     use Regexp::Common qw[Email::Address];
6    
7     subtype 'Email',
8     as 'Str',
9     where { /^$RE{Email}{Address}$/ },
10     message { "$_ is not valid e-mail" };
11    
12 dpavlin 1098 extends 'App::RoomReservation';
13 dpavlin 1086
14 dpavlin 1095 use lib 'lib';
15     use Frey::PPI;
16    
17 dpavlin 1086 has ime => (
18     is => 'rw',
19     isa => 'Str',
20     required => 1,
21     );
22    
23     has prezime => (
24     is => 'rw',
25     isa => 'Str',
26     required => 1,
27     );
28    
29     has institucija => (
30     is => 'rw',
31     isa => 'Str',
32     required => 1,
33     );
34    
35     has zanimanje => (
36     is => 'rw',
37     isa => 'Str',
38     required => 1,
39     );
40    
41     has grad => (
42     is => 'rw',
43     isa => 'Str',
44     required => 1,
45     );
46    
47     has drzava => (
48     is => 'rw',
49     isa => 'Str',
50     required => 1,
51     );
52    
53     has telefon => (
54     is => 'rw',
55     isa => 'Str',
56     required => 1,
57     );
58    
59     has mobitel => (
60     is => 'rw',
61     isa => 'Str',
62     required => 1,
63     );
64    
65     has email => (
66     is => 'rw',
67 dpavlin 1118 isa => 'Email',
68 dpavlin 1086 required => 1,
69     );
70    
71     has email_verify => (
72     is => 'rw',
73 dpavlin 1118 isa => 'Email',
74 dpavlin 1086 required => 1,
75     );
76    
77     has _confirmed => (
78     is => 'rw',
79     isa => 'Bool',
80 dpavlin 1118 # required => 1,
81 dpavlin 1086 default => sub { 0 },
82     );
83    
84 dpavlin 1104 sub BUILD {
85     my $self = shift;
86     die "e-mail not verified\n" unless $self->email eq $self->email_verify;
87     }
88    
89 dpavlin 1095 my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;
90     warn "# cols = ",join(',', @cols), $/;
91    
92 dpavlin 1098 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 dpavlin 1095 sub create_as_markup {
102 dpavlin 1086 my ($self) = @_;
103    
104 dpavlin 1095 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 dpavlin 1098 my $sth = $self->dbh->prepare( $sql );
125 dpavlin 1095 $sth->execute( @vals );
126    
127 dpavlin 1098 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 dpavlin 1086 }
145    
146 dpavlin 1098
147 dpavlin 1086 1;

  ViewVC Help
Powered by ViewVC 1.1.26