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 |
|
with 'App::RoomReservation::Email', 'App::RoomReservation::Messages'; |
15 |
|
|
16 |
|
use lib 'lib'; |
17 |
|
use Frey::PPI; |
18 |
|
|
19 |
has ime => ( |
has ime => ( |
20 |
is => 'rw', |
is => 'rw', |
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 |
sub as_markup { |
has _seat_number => ( |
87 |
|
is => 'rw', |
88 |
|
isa => 'Int', |
89 |
|
); |
90 |
|
|
91 |
|
sub BUILD { |
92 |
|
my $self = shift; |
93 |
|
my $email = $self->email; |
94 |
|
die "e-mail not verified\n" unless $email eq $self->email_verify; |
95 |
|
my $sth = $self->dbh->prepare(qq{ |
96 |
|
select count(*) from reservation where email = ? |
97 |
|
}); |
98 |
|
$sth->execute( $email ); |
99 |
|
my ($registred) = $sth->fetchrow_array; |
100 |
|
if ( $registred ) { |
101 |
|
die qq| |
102 |
|
<big>e-mail address $email allready registred</big> |
103 |
|
| . $self->seat_confirmation_message( email => $email ) |
104 |
|
; |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
|
my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order; |
109 |
|
warn "# cols = ",join(',', @cols), $/; |
110 |
|
|
111 |
|
sub create_as_markup { |
112 |
my ($self) = @_; |
my ($self) = @_; |
113 |
|
|
114 |
$self->ime; |
my @vals; |
115 |
|
my @p; |
116 |
|
|
117 |
|
map { |
118 |
|
push @vals, $self->$_; |
119 |
|
push @p, '?'; |
120 |
|
} @cols; |
121 |
|
|
122 |
|
my $n = $#cols + 1; |
123 |
|
|
124 |
|
my $sql |
125 |
|
= 'insert into reservation (' |
126 |
|
. join(',', @cols) |
127 |
|
. ') values (' |
128 |
|
. join(',', map { '?' } @cols ) |
129 |
|
. ')' |
130 |
|
; |
131 |
|
|
132 |
|
warn "sql: $sql\n"; |
133 |
|
|
134 |
|
my $sth = $self->dbh->prepare( $sql ); |
135 |
|
$sth->execute( @vals ); |
136 |
|
|
137 |
|
return $self->seat_confirmation_message( email => $self->email ); |
138 |
|
|
139 |
} |
} |
140 |
|
|
141 |
|
__PACKAGE__->meta->make_immutable; |
142 |
|
no Moose; |
143 |
|
no Moose::Util::TypeConstraints; |
144 |
|
|
145 |
1; |
1; |