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'; |
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 |
|
die "e-mail not verified\n" unless $self->email eq $self->email_verify; |
94 |
|
my $sth = $self->dbh->prepare(qq{ |
95 |
|
select count(*) from reservation where email = ? |
96 |
|
}); |
97 |
|
$sth->execute( $self->email ); |
98 |
|
my ($registred) = $sth->fetchrow_array; |
99 |
|
die "e-mail address ", $self->email, " allready registred\n" if $registred; |
100 |
|
} |
101 |
|
|
102 |
|
my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order; |
103 |
|
warn "# cols = ",join(',', @cols), $/; |
104 |
|
|
105 |
|
sub token { |
106 |
|
my $self = shift; |
107 |
|
my $sth = $self->dbh->prepare(qq{ |
108 |
|
select md5( id || email ) from reservation where email = ? |
109 |
|
}); |
110 |
|
$sth->execute( $self->email ); |
111 |
|
$sth->fetchrow_array; |
112 |
|
} |
113 |
|
|
114 |
|
sub create_as_markup { |
115 |
my ($self) = @_; |
my ($self) = @_; |
116 |
|
|
117 |
$self->ime; |
my @vals; |
118 |
|
my @p; |
119 |
|
|
120 |
|
map { |
121 |
|
push @vals, $self->$_; |
122 |
|
push @p, '?'; |
123 |
|
} @cols; |
124 |
|
|
125 |
|
my $n = $#cols + 1; |
126 |
|
|
127 |
|
my $sql |
128 |
|
= 'insert into reservation (' |
129 |
|
. join(',', @cols) |
130 |
|
. ') values (' |
131 |
|
. join(',', map { '?' } @cols ) |
132 |
|
. ')' |
133 |
|
; |
134 |
|
|
135 |
|
warn "sql: $sql\n"; |
136 |
|
|
137 |
|
my $sth = $self->dbh->prepare( $sql ); |
138 |
|
$sth->execute( @vals ); |
139 |
|
|
140 |
|
my $url = $self->url_for( 'Confirmation/verify_as_markup?token=' . $self->token ); |
141 |
|
|
142 |
|
$self->send( $self->email, |
143 |
|
'Confirm your reservation for lecture', <<__EMAIL__ |
144 |
|
Please click following link to confirm your reservation for lecture |
145 |
|
and get seat assigned to you. |
146 |
|
|
147 |
|
$url |
148 |
|
__EMAIL__ |
149 |
|
); |
150 |
|
|
151 |
|
return |
152 |
|
$self->ime . ' ' . $self->prezime |
153 |
|
. qq| we have accepted your registration!| |
154 |
|
. qq| |
155 |
|
<div style="color:red"> |
156 |
|
You have to confirm your e-mail address and registration |
157 |
|
by clicking on link which should be in your e-mail INBOX shortly |
158 |
|
</div> |
159 |
|
| |
160 |
|
; |
161 |
} |
} |
162 |
|
|
163 |
|
__PACKAGE__->meta->make_immutable; |
164 |
|
no Moose; |
165 |
|
no Moose::Util::TypeConstraints; |
166 |
|
|
167 |
1; |
1; |