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

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

trunk/lib/App/RoomReservation/Reservation/Confirmation.pm revision 1098 by dpavlin, Sun Jun 28 22:14:22 2009 UTC branches/zimbardo/lib/App/RoomReservation/Confirmation.pm revision 1172 by dpavlin, Sun Jul 5 21:40:16 2009 UTC
# Line 1  Line 1 
1  package App::RoomReservation::Reservation::Confirmation;  package App::RoomReservation::Confirmation;
2  use Moose;  use Moose;
3    
4  extends 'App::RoomReservation';  extends 'App::RoomReservation';
5    
6    with 'App::RoomReservation::Email', 'App::RoomReservation::Messages';
7    
8  has token => (  has token => (
9          is => 'ro',          is => 'ro',
10          isa => 'Str',          isa => 'Str',
# Line 12  has token => ( Line 14  has token => (
14  sub verify_as_markup {  sub verify_as_markup {
15          my ($self) = @_;          my ($self) = @_;
16    
17          my $sth = $self->dbh->prepare(qq{          my $dbh = $self->dbh;
18                  update reservation set _confirmed = true  
19                  where md5(id||email) = ? and _confirmed is false          my $sth = $dbh->prepare(qq{
20                    update reservation
21                    set
22                            _confirmed = true,
23                            _seat_number = (
24                                    select
25                                            min(seat.nr)
26                                    from (select generate_series(1,600) as nr) as seat
27                                    full join reservation on reservation._seat_number = seat.nr
28                                    where id is null
29                                    group by seat.nr
30                                    order by seat.nr asc
31                                    limit 1
32                            )
33                    where
34                            md5(id||email) = ?
35                            and _confirmed is false
36                            and _canceled is false
37          });          });
38          $sth->execute( $self->token );  
39            my $token = $self->token;
40    
41            $sth->execute( $token );
42    
43            if ( $sth->rows == 0 ) {
44                    warn "can't confirm ", $self->token, " check if it's allready confirmed";
45                    $sth = $dbh->prepare(qq{
46                            select 1
47                            from reservation
48                            where
49                                    md5(id||email) = ?
50                                    and _confirmed is true
51                    });
52                    $sth->execute( $token );
53            }
54    
55          if ( $sth->rows == 1 ) {          if ( $sth->rows == 1 ) {
56                  qq|Your <em>reservation has been confirmed</em> and seat is waiting for you|;  
57                    die qq|<error>can't find account associated with $token</error>| unless $sth->rows == 1;
58    
59                    return $self->seat_confirmation_message( token => $token );
60    
61          } else {          } else {
62                  qq|We have problem with your confirmation|                  die qq|<error>Can't find confirmation $token<br>
63                            Did you copy-pasted whole URL in your browser?</error>|;
64          }          }
65  }  }
66    
67  sub cancel_as_markup {  sub cancel_as_markup {
68          my ($self) = @_;          my ($self) = @_;
69    
70          my $sth = $self->dbh->prepare(qq{          my $dbh = $self->dbh;
71                  update reservation set _confirmed = false  
72                  where md5(id||email) = ? and _confirmed is true          my $sth = $dbh->prepare(qq{
73                    update reservation
74                    set
75                            _canceled = true,
76                            _seat_number = null
77                    where
78                            md5(id||email) = ?
79    --                      and _confirmed is true
80          });          });
81          $sth->execute( $self->token );          $sth->execute( $self->token );
82    
83          if ( $sth->rows == 1 ) {          if ( $sth->rows == 1 ) {
84                  qq|Your <em>reservation is canceled</em>, thanks for your effort to provide seat to somebody else|;                  qq|
85                            Your <em>reservation is canceled</em>, thanks for your effort to provide seat to somebody else
86                    |;
87          } else {          } else {
88                  qq|We have problem with cancelation|                  die qq|<error>Can't find reservation which you are trying to cancel.<br>
89                            Did you copy-pasted whole URL in your browser?</error>|;
90          }          }
91  }  }
92    
93    __PACKAGE__->meta->make_immutable;
94    no Moose;
95    
96  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26