line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package meon::Web::Form::MemberRegistration; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
9496922
|
use 5.010; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
145
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1778
|
use List::MoreUtils 'uniq'; |
|
2
|
|
|
|
|
3536
|
|
|
2
|
|
|
|
|
444
|
|
6
|
2
|
|
|
2
|
|
1895
|
use Email::MIME; |
|
2
|
|
|
|
|
110739
|
|
|
2
|
|
|
|
|
15
|
|
7
|
2
|
|
|
2
|
|
1123
|
use Email::Sender::Simple qw(sendmail); |
|
2
|
|
|
|
|
226957
|
|
|
2
|
|
|
|
|
12
|
|
8
|
2
|
|
|
2
|
|
1802
|
use Data::Dumper; |
|
2
|
|
|
|
|
10475
|
|
|
2
|
|
|
|
|
115
|
|
9
|
2
|
|
|
2
|
|
918
|
use meon::Web::Util; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use meon::Web::Member; |
11
|
|
|
|
|
|
|
use Path::Class 'dir'; |
12
|
|
|
|
|
|
|
use Data::Header::Fields; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use HTML::FormHandler::Moose; |
15
|
|
|
|
|
|
|
extends 'HTML::FormHandler'; |
16
|
|
|
|
|
|
|
with 'meon::Web::Role::Form'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has_field 'submit' => ( type => 'Submit', value => 'Submit', ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
before 'validate' => sub { |
21
|
|
|
|
|
|
|
my ($self) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$self->add_form_error('Are you real?') |
24
|
|
|
|
|
|
|
if $self->c->req->param('yreo'); |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _build_configured_field_list { |
28
|
|
|
|
|
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# check if there are mandatory settings |
31
|
|
|
|
|
|
|
$self->get_config_text('rcpt-to'); |
32
|
|
|
|
|
|
|
$self->get_config_text('subject'); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub submitted { |
36
|
|
|
|
|
|
|
my ($self) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $c = $self->c; |
39
|
|
|
|
|
|
|
my $xpc = meon::Web::Util->xpc; |
40
|
|
|
|
|
|
|
my $xml = $c->model('ResponseXML')->dom; |
41
|
|
|
|
|
|
|
my %params = %{$c->req->params}; |
42
|
|
|
|
|
|
|
$c->log->debug(__PACKAGE__.' '.Data::Dumper::Dumper($c->req->params)) |
43
|
|
|
|
|
|
|
if $c->debug; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $email = $c->req->param('email'); |
46
|
|
|
|
|
|
|
my $password = $c->req->param('password') // ''; |
47
|
|
|
|
|
|
|
my $all_required_set = 1; |
48
|
|
|
|
|
|
|
my $members_folder = $c->default_auth_store->folder; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $login = eval { $self->get_config_text('login') }; |
51
|
|
|
|
|
|
|
if ($login) { |
52
|
|
|
|
|
|
|
my $member = meon::Web::Member->find_by_email( |
53
|
|
|
|
|
|
|
members_folder => $members_folder, |
54
|
|
|
|
|
|
|
email => $email, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
if ($member) { |
57
|
|
|
|
|
|
|
if ($member->user->check_password($password)) { |
58
|
|
|
|
|
|
|
my $username = $member->username; |
59
|
|
|
|
|
|
|
$c->set_authenticated($c->find_user({ username => $member->user->username })); |
60
|
|
|
|
|
|
|
return $self->detach; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
|
|
|
|
|
|
$all_required_set = 0; |
64
|
|
|
|
|
|
|
$c->session->{form_input_errors}->{'password'} = 'wrong password'; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my %inputs = map { $_->getAttribute('name') => $_ } $xpc->findnodes('.//x:input|.//x:select|.//x:textarea',$xml); |
71
|
|
|
|
|
|
|
foreach my $key (keys %params) { |
72
|
|
|
|
|
|
|
next unless my $input = $inputs{$key}; |
73
|
|
|
|
|
|
|
my $value = $params{$key} // ''; |
74
|
|
|
|
|
|
|
$value =~ s/\r//g; |
75
|
|
|
|
|
|
|
$value = undef if (length($value) == 0); |
76
|
|
|
|
|
|
|
if (!defined($value) && $input->getAttribute('required')) { |
77
|
|
|
|
|
|
|
$all_required_set = 0; |
78
|
|
|
|
|
|
|
$c->session->{form_input_errors}->{$key} = 'Required'; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
foreach my $input (values %inputs) { |
82
|
|
|
|
|
|
|
my $input_name = $input->getAttribute('name'); |
83
|
|
|
|
|
|
|
my $input_value = $params{$input_name} // ''; |
84
|
|
|
|
|
|
|
next if (($input->getAttribute('type') // '') eq 'submit'); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
given ($input->nodeName) { |
87
|
|
|
|
|
|
|
when ('select') { |
88
|
|
|
|
|
|
|
my ($option) = $xpc->findnodes('.//x:option[@value="'.$input_value.'"]',$input); |
89
|
|
|
|
|
|
|
$option->setAttribute('selected' => 'selected') |
90
|
|
|
|
|
|
|
if $option; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
when ('textarea') { |
93
|
|
|
|
|
|
|
$input->removeChildNodes(); |
94
|
|
|
|
|
|
|
$input->appendText($input_value) |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
default { |
97
|
|
|
|
|
|
|
$input->setAttribute(value => $input_value); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
return unless $all_required_set; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $members_folder = $c->default_auth_store->folder; |
104
|
|
|
|
|
|
|
my $username = meon::Web::Util->username_cleanup( |
105
|
|
|
|
|
|
|
($c->req->param('username') // $c->req->param('name') // $c->req->param('email') // ''), |
106
|
|
|
|
|
|
|
$members_folder, |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
$c->req->params->{username} = $username; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $member_folder = dir($members_folder, $username); |
111
|
|
|
|
|
|
|
mkdir($member_folder) or die 'failed to create member folder: '.$!; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $rcpt_to = $self->get_config_text('rcpt-to'); |
114
|
|
|
|
|
|
|
my $subject = $self->get_config_text('subject'); |
115
|
|
|
|
|
|
|
$subject .= ' - '.$c->req->param('name') |
116
|
|
|
|
|
|
|
if $c->req->param('name'); |
117
|
|
|
|
|
|
|
my $detach = $self->get_config_text('detach'); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $email_content = ''; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my (@input_names) = |
122
|
|
|
|
|
|
|
uniq |
123
|
|
|
|
|
|
|
grep { defined $_ } |
124
|
|
|
|
|
|
|
map { $_->getAttribute('name') } |
125
|
|
|
|
|
|
|
grep { $_->getAttribute('type') !~ /password/i } |
126
|
|
|
|
|
|
|
$xpc->findnodes('//x:form//x:input | //x:form//x:textarea',$xml); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my @args; |
129
|
|
|
|
|
|
|
my $dhf = Data::Header::Fields->new; |
130
|
|
|
|
|
|
|
foreach my $input_name (@input_names) { |
131
|
|
|
|
|
|
|
my $input_value = $c->req->param($input_name) // ''; |
132
|
|
|
|
|
|
|
next unless length $input_value; |
133
|
|
|
|
|
|
|
push(@args, [ $input_name => $input_value ]); |
134
|
|
|
|
|
|
|
$dhf->set_value($input_name => ' '.$input_value); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
$email_content .= $dhf->encode; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# create user xml file |
139
|
|
|
|
|
|
|
my $member = meon::Web::Member->new( |
140
|
|
|
|
|
|
|
members_folder => $members_folder, |
141
|
|
|
|
|
|
|
username => $username, |
142
|
|
|
|
|
|
|
); |
143
|
|
|
|
|
|
|
$member->create( |
144
|
|
|
|
|
|
|
name => $c->req->param('name') // '', |
145
|
|
|
|
|
|
|
email => $c->req->param('email') // '', |
146
|
|
|
|
|
|
|
address => $c->req->param('address') // '', |
147
|
|
|
|
|
|
|
lat => $c->req->param('lat') // '', |
148
|
|
|
|
|
|
|
lng => $c->req->param('lng') // '', |
149
|
|
|
|
|
|
|
registration_form => $email_content, |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
if ($password) { |
152
|
|
|
|
|
|
|
$member->user->set_password($password); |
153
|
|
|
|
|
|
|
if (eval { $self->get_config_text('auto-activate') } // 0 ) { |
154
|
|
|
|
|
|
|
$member->user->set_status('active'); |
155
|
|
|
|
|
|
|
$c->set_authenticated($c->find_user({ username => $member->user->username })); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
meon::Web::Util->send_email( |
160
|
|
|
|
|
|
|
from => $c->req->param('email'), |
161
|
|
|
|
|
|
|
to => $rcpt_to, |
162
|
|
|
|
|
|
|
subject => $subject, |
163
|
|
|
|
|
|
|
text => $email_content, |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
$self->detach($detach); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
no HTML::FormHandler::Moose; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |