/[Frey]/branches/zimbardo/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 /branches/zimbardo/lib/App/RoomReservation/Reservation.pm

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

trunk/lib/App/RoomReservation/Reservation.pm revision 1098 by dpavlin, Sun Jun 28 22:14:22 2009 UTC branches/zimbardo/lib/App/RoomReservation/Reservation.pm revision 1173 by dpavlin, Sun Jul 5 21:40:54 2009 UTC
# Line 1  Line 1 
1  package App::RoomReservation::Reservation;  package App::RoomReservation::Reservation;
2  use Moose;  use Moose;
3    
4    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 { qq|<error>$_ nije valjana e-mail adresa / $_ is not valid e-mail address</error>| };
11    
12  extends 'App::RoomReservation';  extends 'App::RoomReservation';
13    
14    with 'App::RoomReservation::Email', 'App::RoomReservation::Messages';
15    
16  use lib 'lib';  use lib 'lib';
17  use Frey::PPI;  use Frey::PPI;
18    
# Line 51  has telefon => ( Line 61  has telefon => (
61  has mobitel => (  has mobitel => (
62          is => 'rw',          is => 'rw',
63          isa => 'Str',          isa => 'Str',
64          required => 1,          default => '', # FIXME without this we get undef in form
65  );  );
66    
67  has email => (  has email => (
68          is => 'rw',          is => 'rw',
69          isa => 'Str',          isa => 'Email',
70          required => 1,          required => 1,
71  );  );
72    
73  has email_verify => (  has email_verify => (
74          is => 'rw',          is => 'rw',
75          isa => 'Str',          isa => 'Email',
76          required => 1,          required => 1,
77  );  );
78    
79  has _confirmed => (  has _confirmed => (
80          is => 'rw',          is => 'rw',
81          isa => 'Bool',          isa => 'Bool',
82          required => 1,  #       required => 1,
83          default => sub { 0 },          default => sub { 0 },
84  );  );
85    
86  my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;  has _seat_number => (
87  warn "# cols = ",join(',', @cols), $/;          is => 'rw',
88            isa => 'Int',
89    );
90    
91    has _canceled => (
92            is => 'rw',
93            isa => 'Bool',
94            default => sub { 0 },
95    );
96    
97  sub token {  sub form_labels {{
98          my ( $self ) = @_;          ime => 'Ime / Name',
99            prezime => 'Prezime / Surname',
100            institucija => 'Institucija / Institution',
101            zanimanje => 'Zanimanje / Profession',
102            grad => 'Grad / City',
103            drzava => 'Država / Country',
104            telefon => 'Telefon / Phone',
105            mobitel => 'Mobitel / Cellular phone',
106            email => 'e-mail',
107            verify => 'ponovo / again',
108            submit => 'Pošalji / Submit', # submit button
109    }}
110    
111    sub BUILD {
112          my $self = shift;          my $self = shift;
113            my $email = $self->email;
114            die qq|<error>e-mail addresses not same</error>| unless $email eq $self->email_verify;
115          my $sth = $self->dbh->prepare(qq{          my $sth = $self->dbh->prepare(qq{
116                  select md5( id || email ) from reservation where email = ?                  select count(*) from reservation where email = ?
117          });          });
118          $sth->execute( $self->email );          $sth->execute( $email );
119          $sth->fetchrow_array;          my ($registred) = $sth->fetchrow_array;
120            if ( $registred ) {
121                    die
122                    qq|
123                            <error>
124                            <big>e-mail $email je već registriran / allready registred</big>
125                            <br><br>
126                    |
127                    . $self->seat_confirmation_message( email => $email )
128                    . qq|
129                            </error>
130                    |
131                    ;
132            }
133  }  }
134    
135    my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;
136    warn "# cols = ",join(',', @cols), $/;
137    
138  sub create_as_markup {  sub create_as_markup {
139          my ($self) = @_;          my ($self) = @_;
140    
# Line 112  sub create_as_markup { Line 161  sub create_as_markup {
161          my $sth = $self->dbh->prepare( $sql );          my $sth = $self->dbh->prepare( $sql );
162          $sth->execute( @vals );          $sth->execute( @vals );
163    
164          return          return $self->seat_confirmation_message( email => $self->email );
165                  $self->ime . ' ' . $self->prezime  
                 . qq| we have accepted your registration!|  
                 . qq|  
                         <div style="color:red">  
                         You have to confirm your e-mail address and registration  
                         by clicking on link which should be in your e-mail INBOX shortly  
                         </div>  
                 |  
                 . qq|<a href="/App::RoomReservation::Reservation::Confirmation/verify_as_markup?token=|  
                 . $self->token  
                 . qq|">verify</a>|  
                 . ' or '  
                 . qq|<a href="/App::RoomReservation::Reservation::Confirmation/cancel_as_markup?token=|  
                 . $self->token  
                 . qq|">cancel</a>|  
                 ;  
166  }  }
167    
168    __PACKAGE__->meta->make_immutable;
169    no Moose;
170    no Moose::Util::TypeConstraints;
171    
172  1;  1;

Legend:
Removed from v.1098  
changed lines
  Added in v.1173

  ViewVC Help
Powered by ViewVC 1.1.26