1 |
dpavlin |
1086 |
package App::RoomReservation::Reservation; |
2 |
|
|
use Moose; |
3 |
|
|
|
4 |
dpavlin |
1118 |
use Moose::Util::TypeConstraints; |
5 |
|
|
use Regexp::Common qw[Email::Address]; |
6 |
|
|
|
7 |
|
|
subtype 'Email', |
8 |
|
|
as 'Str', |
9 |
|
|
where { /^$RE{Email}{Address}$/ }, |
10 |
|
|
message { "$_ is not valid e-mail" }; |
11 |
|
|
|
12 |
dpavlin |
1098 |
extends 'App::RoomReservation'; |
13 |
dpavlin |
1086 |
|
14 |
dpavlin |
1134 |
with 'App::RoomReservation::Email'; |
15 |
|
|
|
16 |
dpavlin |
1095 |
use lib 'lib'; |
17 |
|
|
use Frey::PPI; |
18 |
|
|
|
19 |
dpavlin |
1086 |
has ime => ( |
20 |
|
|
is => 'rw', |
21 |
|
|
isa => 'Str', |
22 |
|
|
required => 1, |
23 |
|
|
); |
24 |
|
|
|
25 |
|
|
has prezime => ( |
26 |
|
|
is => 'rw', |
27 |
|
|
isa => 'Str', |
28 |
|
|
required => 1, |
29 |
|
|
); |
30 |
|
|
|
31 |
|
|
has institucija => ( |
32 |
|
|
is => 'rw', |
33 |
|
|
isa => 'Str', |
34 |
|
|
required => 1, |
35 |
|
|
); |
36 |
|
|
|
37 |
|
|
has zanimanje => ( |
38 |
|
|
is => 'rw', |
39 |
|
|
isa => 'Str', |
40 |
|
|
required => 1, |
41 |
|
|
); |
42 |
|
|
|
43 |
|
|
has grad => ( |
44 |
|
|
is => 'rw', |
45 |
|
|
isa => 'Str', |
46 |
|
|
required => 1, |
47 |
|
|
); |
48 |
|
|
|
49 |
|
|
has drzava => ( |
50 |
|
|
is => 'rw', |
51 |
|
|
isa => 'Str', |
52 |
|
|
required => 1, |
53 |
|
|
); |
54 |
|
|
|
55 |
|
|
has telefon => ( |
56 |
|
|
is => 'rw', |
57 |
|
|
isa => 'Str', |
58 |
|
|
required => 1, |
59 |
|
|
); |
60 |
|
|
|
61 |
|
|
has mobitel => ( |
62 |
|
|
is => 'rw', |
63 |
|
|
isa => 'Str', |
64 |
|
|
required => 1, |
65 |
|
|
); |
66 |
|
|
|
67 |
|
|
has email => ( |
68 |
|
|
is => 'rw', |
69 |
dpavlin |
1118 |
isa => 'Email', |
70 |
dpavlin |
1086 |
required => 1, |
71 |
|
|
); |
72 |
|
|
|
73 |
|
|
has email_verify => ( |
74 |
|
|
is => 'rw', |
75 |
dpavlin |
1118 |
isa => 'Email', |
76 |
dpavlin |
1086 |
required => 1, |
77 |
|
|
); |
78 |
|
|
|
79 |
|
|
has _confirmed => ( |
80 |
|
|
is => 'rw', |
81 |
|
|
isa => 'Bool', |
82 |
dpavlin |
1118 |
# required => 1, |
83 |
dpavlin |
1086 |
default => sub { 0 }, |
84 |
|
|
); |
85 |
|
|
|
86 |
dpavlin |
1121 |
has _seat_number => ( |
87 |
|
|
is => 'rw', |
88 |
|
|
isa => 'Int', |
89 |
|
|
); |
90 |
|
|
|
91 |
dpavlin |
1104 |
sub BUILD { |
92 |
|
|
my $self = shift; |
93 |
|
|
die "e-mail not verified\n" unless $self->email eq $self->email_verify; |
94 |
dpavlin |
1120 |
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 |
dpavlin |
1104 |
} |
101 |
|
|
|
102 |
dpavlin |
1095 |
my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order; |
103 |
|
|
warn "# cols = ",join(',', @cols), $/; |
104 |
|
|
|
105 |
dpavlin |
1098 |
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 |
dpavlin |
1095 |
sub create_as_markup { |
115 |
dpavlin |
1086 |
my ($self) = @_; |
116 |
|
|
|
117 |
dpavlin |
1095 |
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 |
dpavlin |
1098 |
my $sth = $self->dbh->prepare( $sql ); |
138 |
dpavlin |
1095 |
$sth->execute( @vals ); |
139 |
|
|
|
140 |
dpavlin |
1134 |
my $token = $self->token; |
141 |
|
|
$self->send( $self->email, |
142 |
|
|
'Confirm your reservation for lecture', <<__EMAIL__ |
143 |
|
|
Please click following link to confirm your reservation for lecture |
144 |
|
|
and get seat assigned to you. |
145 |
|
|
|
146 |
|
|
http://FREY_HOSTNAME/App::RoomReservation::Confirmation/verify_as_markup?token=$token |
147 |
|
|
__EMAIL__ |
148 |
|
|
); |
149 |
|
|
|
150 |
dpavlin |
1098 |
return |
151 |
|
|
$self->ime . ' ' . $self->prezime |
152 |
|
|
. qq| we have accepted your registration!| |
153 |
|
|
. qq| |
154 |
|
|
<div style="color:red"> |
155 |
|
|
You have to confirm your e-mail address and registration |
156 |
|
|
by clicking on link which should be in your e-mail INBOX shortly |
157 |
|
|
</div> |
158 |
|
|
| |
159 |
|
|
; |
160 |
dpavlin |
1086 |
} |
161 |
|
|
|
162 |
dpavlin |
1133 |
__PACKAGE__->meta->make_immutable; |
163 |
|
|
no Moose; |
164 |
|
|
no Moose::Util::TypeConstraints; |
165 |
dpavlin |
1098 |
|
166 |
dpavlin |
1086 |
1; |