/[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 1121 by dpavlin, Tue Jun 30 13:24:03 2009 UTC revision 1175 by dpavlin, Mon Jul 6 20:27:57 2009 UTC
# Line 7  use Regexp::Common qw[Email::Address]; Line 7  use Regexp::Common qw[Email::Address];
7  subtype 'Email',  subtype 'Email',
8          as 'Str',          as 'Str',
9          where { /^$RE{Email}{Address}$/ },          where { /^$RE{Email}{Address}$/ },
10          message { "$_ is not valid e-mail" };          message { qq|<error>$_ 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 59  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 => (
# Line 86  has _seat_number => ( Line 88  has _seat_number => (
88          isa => 'Int',          isa => 'Int',
89  );  );
90    
91    has _canceled => (
92            is => 'rw',
93            isa => 'Bool',
94            default => sub { 0 },
95    );
96    
97    sub form_labels {{
98            ime => 'Ime',
99            prezime => 'Prezime',
100            institucija => 'Institucija',
101            zanimanje => 'Zanimanje',
102            grad => 'Grad',
103            drzava => 'Država',
104            telefon => 'Telefon',
105            mobitel => 'Mobitel',
106            email => 'e-mail adresa',
107            verify => 'unesite ponovo',
108            submit => 'Pošalji', # submit button
109    }}
110    
111    sub form_value_len {
112            my $self = shift;
113            my $sth = $self->dbh->prepare(qq{
114                    select * from reservation limit 1
115            });
116            $sth->execute;
117            my @columns = $sth->fetchrow_array;
118    
119            $sth = $self->dbh->prepare(qq{
120                    select
121            } . join(',', map { "max(length($_)) as $_" } grep { !/^_/ && !/id/ } @{ $sth->{NAME} } ) . qq{
122                    from reservation
123            });
124            $sth->execute;
125            my $max_len = $sth->fetchrow_hashref;
126            warn "# max_len = ", $self->dump( $max_len );
127            return $max_len;
128    }
129    
130  sub BUILD {  sub BUILD {
131          my $self = shift;          my $self = shift;
132          die "e-mail not verified\n" unless $self->email eq $self->email_verify;          my $email = $self->email;
133            die qq|<error>e-mail addresses not same</error>| unless $email eq $self->email_verify;
134          my $sth = $self->dbh->prepare(qq{          my $sth = $self->dbh->prepare(qq{
135                  select count(*) from reservation where email = ?                  select count(*) from reservation where email = ?
136          });          });
137          $sth->execute( $self->email );          $sth->execute( $email );
138          my ($registred) = $sth->fetchrow_array;          my ($registred) = $sth->fetchrow_array;
139          die "e-mail address ", $self->email, " allready registred\n" if $registred;          if ( $registred ) {
140                    die
141                    qq|
142                            <error>
143                            <big>e-mail address $email allready registred</big>
144                    |
145                    . $self->seat_confirmation_message( email => $email )
146                    . qq|
147                            </error>
148                    |
149                    ;
150            }
151  }  }
152    
153  my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;  my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;
154  warn "# cols = ",join(',', @cols), $/;  warn "# cols = ",join(',', @cols), $/;
155    
 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;  
 }  
   
156  sub create_as_markup {  sub create_as_markup {
157          my ($self) = @_;          my ($self) = @_;
158    
# Line 135  sub create_as_markup { Line 179  sub create_as_markup {
179          my $sth = $self->dbh->prepare( $sql );          my $sth = $self->dbh->prepare( $sql );
180          $sth->execute( @vals );          $sth->execute( @vals );
181    
182          return          return $self->seat_confirmation_message( email => $self->email );
183                  $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>|  
                 ;  
184  }  }
185    
186    __PACKAGE__->meta->make_immutable;
187    no Moose;
188    no Moose::Util::TypeConstraints;
189    
190  1;  1;

Legend:
Removed from v.1121  
changed lines
  Added in v.1175

  ViewVC Help
Powered by ViewVC 1.1.26