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 |
|
use lib 'lib'; |
15 |
|
use Frey::PPI; |
16 |
|
|
17 |
has ime => ( |
has ime => ( |
18 |
is => 'rw', |
is => 'rw', |
64 |
|
|
65 |
has email => ( |
has email => ( |
66 |
is => 'rw', |
is => 'rw', |
67 |
isa => 'Str', |
isa => 'Email', |
68 |
required => 1, |
required => 1, |
69 |
); |
); |
70 |
|
|
71 |
has email_verify => ( |
has email_verify => ( |
72 |
is => 'rw', |
is => 'rw', |
73 |
isa => 'Str', |
isa => 'Email', |
74 |
required => 1, |
required => 1, |
75 |
); |
); |
76 |
|
|
77 |
has _confirmed => ( |
has _confirmed => ( |
78 |
is => 'rw', |
is => 'rw', |
79 |
isa => 'Bool', |
isa => 'Bool', |
80 |
required => 1, |
# required => 1, |
81 |
default => sub { 0 }, |
default => sub { 0 }, |
82 |
); |
); |
83 |
|
|
84 |
sub as_markup { |
has _seat_number => ( |
85 |
|
is => 'rw', |
86 |
|
isa => 'Int', |
87 |
|
); |
88 |
|
|
89 |
|
sub BUILD { |
90 |
|
my $self = shift; |
91 |
|
die "e-mail not verified\n" unless $self->email eq $self->email_verify; |
92 |
|
my $sth = $self->dbh->prepare(qq{ |
93 |
|
select count(*) from reservation where email = ? |
94 |
|
}); |
95 |
|
$sth->execute( $self->email ); |
96 |
|
my ($registred) = $sth->fetchrow_array; |
97 |
|
die "e-mail address ", $self->email, " allready registred\n" if $registred; |
98 |
|
} |
99 |
|
|
100 |
|
my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order; |
101 |
|
warn "# cols = ",join(',', @cols), $/; |
102 |
|
|
103 |
|
sub token { |
104 |
|
my $self = shift; |
105 |
|
my $sth = $self->dbh->prepare(qq{ |
106 |
|
select md5( id || email ) from reservation where email = ? |
107 |
|
}); |
108 |
|
$sth->execute( $self->email ); |
109 |
|
$sth->fetchrow_array; |
110 |
|
} |
111 |
|
|
112 |
|
sub create_as_markup { |
113 |
my ($self) = @_; |
my ($self) = @_; |
114 |
|
|
115 |
$self->ime; |
my @vals; |
116 |
|
my @p; |
117 |
|
|
118 |
|
map { |
119 |
|
push @vals, $self->$_; |
120 |
|
push @p, '?'; |
121 |
|
} @cols; |
122 |
|
|
123 |
|
my $n = $#cols + 1; |
124 |
|
|
125 |
|
my $sql |
126 |
|
= 'insert into reservation (' |
127 |
|
. join(',', @cols) |
128 |
|
. ') values (' |
129 |
|
. join(',', map { '?' } @cols ) |
130 |
|
. ')' |
131 |
|
; |
132 |
|
|
133 |
|
warn "sql: $sql\n"; |
134 |
|
|
135 |
|
my $sth = $self->dbh->prepare( $sql ); |
136 |
|
$sth->execute( @vals ); |
137 |
|
|
138 |
|
return |
139 |
|
$self->ime . ' ' . $self->prezime |
140 |
|
. qq| we have accepted your registration!| |
141 |
|
. qq| |
142 |
|
<div style="color:red"> |
143 |
|
You have to confirm your e-mail address and registration |
144 |
|
by clicking on link which should be in your e-mail INBOX shortly |
145 |
|
</div> |
146 |
|
| |
147 |
|
. qq|<a href="/App::RoomReservation::Confirmation/verify_as_markup?token=| |
148 |
|
. $self->token |
149 |
|
. qq|">verify</a>| |
150 |
|
. ' or ' |
151 |
|
. qq|<a href="/App::RoomReservation::Confirmation/cancel_as_markup?token=| |
152 |
|
. $self->token |
153 |
|
. qq|">cancel</a>| |
154 |
|
; |
155 |
} |
} |
156 |
|
|
157 |
|
__PACKAGE__->meta->make_immutable; |
158 |
|
no Moose; |
159 |
|
no Moose::Util::TypeConstraints; |
160 |
|
|
161 |
1; |
1; |