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 { |
sub BUILD { |
85 |
|
my $self = shift; |
86 |
|
die "e-mail not verified\n" unless $self->email eq $self->email_verify; |
87 |
|
my $sth = $self->dbh->prepare(qq{ |
88 |
|
select count(*) from reservation where email = ? |
89 |
|
}); |
90 |
|
$sth->execute( $self->email ); |
91 |
|
my ($registred) = $sth->fetchrow_array; |
92 |
|
die "e-mail address ", $self->email, " allready registred\n" if $registred; |
93 |
|
} |
94 |
|
|
95 |
|
my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order; |
96 |
|
warn "# cols = ",join(',', @cols), $/; |
97 |
|
|
98 |
|
sub token { |
99 |
|
my $self = shift; |
100 |
|
my $sth = $self->dbh->prepare(qq{ |
101 |
|
select md5( id || email ) from reservation where email = ? |
102 |
|
}); |
103 |
|
$sth->execute( $self->email ); |
104 |
|
$sth->fetchrow_array; |
105 |
|
} |
106 |
|
|
107 |
|
sub create_as_markup { |
108 |
my ($self) = @_; |
my ($self) = @_; |
109 |
|
|
110 |
$self->ime; |
my @vals; |
111 |
|
my @p; |
112 |
|
|
113 |
|
map { |
114 |
|
push @vals, $self->$_; |
115 |
|
push @p, '?'; |
116 |
|
} @cols; |
117 |
|
|
118 |
|
my $n = $#cols + 1; |
119 |
|
|
120 |
|
my $sql |
121 |
|
= 'insert into reservation (' |
122 |
|
. join(',', @cols) |
123 |
|
. ') values (' |
124 |
|
. join(',', map { '?' } @cols ) |
125 |
|
. ')' |
126 |
|
; |
127 |
|
|
128 |
|
warn "sql: $sql\n"; |
129 |
|
|
130 |
|
my $sth = $self->dbh->prepare( $sql ); |
131 |
|
$sth->execute( @vals ); |
132 |
|
|
133 |
|
return |
134 |
|
$self->ime . ' ' . $self->prezime |
135 |
|
. qq| we have accepted your registration!| |
136 |
|
. qq| |
137 |
|
<div style="color:red"> |
138 |
|
You have to confirm your e-mail address and registration |
139 |
|
by clicking on link which should be in your e-mail INBOX shortly |
140 |
|
</div> |
141 |
|
| |
142 |
|
. qq|<a href="/App::RoomReservation::Reservation::Confirmation/verify_as_markup?token=| |
143 |
|
. $self->token |
144 |
|
. qq|">verify</a>| |
145 |
|
. ' or ' |
146 |
|
. qq|<a href="/App::RoomReservation::Reservation::Confirmation/cancel_as_markup?token=| |
147 |
|
. $self->token |
148 |
|
. qq|">cancel</a>| |
149 |
|
; |
150 |
} |
} |
151 |
|
|
152 |
|
|
153 |
1; |
1; |