line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::App::Register; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
77164
|
use base qw(Plack::Component::Tags::HTML); |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
1037
|
|
4
|
2
|
|
|
2
|
|
162567
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
43
|
|
5
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
61
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
13
|
use Plack::Util::Accessor qw(generator message_cb redirect_register redirect_error register_cb title); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
8
|
2
|
|
|
2
|
|
1178
|
use Plack::Request; |
|
2
|
|
|
|
|
115720
|
|
|
2
|
|
|
|
|
70
|
|
9
|
2
|
|
|
2
|
|
912
|
use Plack::Response; |
|
2
|
|
|
|
|
2294
|
|
|
2
|
|
|
|
|
71
|
|
10
|
2
|
|
|
2
|
|
861
|
use Plack::Session; |
|
2
|
|
|
|
|
954
|
|
|
2
|
|
|
|
|
62
|
|
11
|
2
|
|
|
2
|
|
944
|
use Tags::HTML::Container; |
|
2
|
|
|
|
|
2326
|
|
|
2
|
|
|
|
|
59
|
|
12
|
2
|
|
|
2
|
|
988
|
use Tags::HTML::Login::Register; |
|
2
|
|
|
|
|
3213
|
|
|
2
|
|
|
|
|
1449
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = 0.01; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _css { |
17
|
0
|
|
|
0
|
|
|
my ($self, $env) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
$self->{'_container'}->process_css; |
20
|
0
|
|
|
|
|
|
$self->{'_login_register'}->process_css({ |
21
|
|
|
|
|
|
|
'info' => 'blue', |
22
|
|
|
|
|
|
|
'error' => 'red', |
23
|
|
|
|
|
|
|
}); |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
return; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _message { |
29
|
0
|
|
|
0
|
|
|
my ($self, $env, $message_type, $message) = @_; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
if (defined $self->message_cb) { |
32
|
0
|
|
|
|
|
|
$self->message_cb->($env, $message_type, $message); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _prepare_app { |
39
|
0
|
|
|
0
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Defaults which rewrite defaults in module which I am inheriting. |
42
|
0
|
0
|
|
|
|
|
if (! defined $self->generator) { |
43
|
0
|
|
|
|
|
|
$self->generator(__PACKAGE__.'; Version: '.$VERSION); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if (! defined $self->title) { |
47
|
0
|
|
|
|
|
|
$self->title('Register page'); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Inherite defaults. |
51
|
0
|
|
|
|
|
|
$self->SUPER::_prepare_app; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Defaults from this module. |
54
|
0
|
|
|
|
|
|
my %p = ( |
55
|
|
|
|
|
|
|
'css' => $self->css, |
56
|
|
|
|
|
|
|
'tags' => $self->tags, |
57
|
|
|
|
|
|
|
); |
58
|
0
|
|
|
|
|
|
$self->{'_login_register'} = Tags::HTML::Login::Register->new(%p); |
59
|
0
|
|
|
|
|
|
$self->{'_container'} = Tags::HTML::Container->new(%p); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _process_actions { |
65
|
0
|
|
|
0
|
|
|
my ($self, $env) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
0
|
|
|
|
if (defined $self->register_cb && $env->{'REQUEST_METHOD'} eq 'POST') { |
68
|
0
|
|
|
|
|
|
my $req = Plack::Request->new($env); |
69
|
0
|
|
|
|
|
|
my $body_params_hr = $req->body_parameters; |
70
|
0
|
|
|
|
|
|
my ($status, $messages_ar) = $self->_register_check($env, $body_params_hr); |
71
|
0
|
|
|
|
|
|
my $res = Plack::Response->new; |
72
|
0
|
0
|
|
|
|
|
if ($status) { |
73
|
0
|
0
|
|
|
|
|
if ($self->register_cb->($env, $body_params_hr->{'username'}, |
74
|
|
|
|
|
|
|
$body_params_hr->{'password1'})) { |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self->_message($env, 'info', |
77
|
|
|
|
|
|
|
"User '$body_params_hr->{'username'}' is registered."); |
78
|
0
|
|
|
|
|
|
$res->redirect($self->redirect_register); |
79
|
|
|
|
|
|
|
} else { |
80
|
0
|
|
|
|
|
|
$res->redirect($self->redirect_error); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} else { |
83
|
0
|
|
|
|
|
|
$res->redirect($self->redirect_error); |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
$self->psgi_app($res->finalize); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _register_check { |
92
|
0
|
|
|
0
|
|
|
my ($self, $env, $body_parameters_hr) = @_; |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
0
|
|
|
|
if (! exists $body_parameters_hr->{'register'} |
95
|
|
|
|
|
|
|
|| $body_parameters_hr->{'register'} ne 'register') { |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$self->_message($env, 'error', 'There is no register POST.'); |
98
|
0
|
|
|
|
|
|
return 0; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
0
|
0
|
|
|
|
if (! defined $body_parameters_hr->{'username'} || ! $body_parameters_hr->{'username'}) { |
101
|
0
|
|
|
|
|
|
$self->_message($env, 'error', "Parameter 'username' doesn't defined."); |
102
|
0
|
|
|
|
|
|
return 0; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
0
|
0
|
|
|
|
if (! defined $body_parameters_hr->{'password1'} || ! $body_parameters_hr->{'password1'}) { |
105
|
0
|
|
|
|
|
|
$self->_message($env, 'error', "Parameter 'password1' doesn't defined."); |
106
|
0
|
|
|
|
|
|
return 0; |
107
|
|
|
|
|
|
|
} |
108
|
0
|
0
|
0
|
|
|
|
if (! defined $body_parameters_hr->{'password2'} || ! $body_parameters_hr->{'password2'}) { |
109
|
0
|
|
|
|
|
|
$self->_message($env, 'error', "Parameter 'password2' doesn't defined."); |
110
|
0
|
|
|
|
|
|
return 0; |
111
|
|
|
|
|
|
|
} |
112
|
0
|
0
|
|
|
|
|
if ($body_parameters_hr->{'password1'} ne $body_parameters_hr->{'password2'}) { |
113
|
0
|
|
|
|
|
|
$self->_message($env, 'error', 'Passwords are not same.'); |
114
|
0
|
|
|
|
|
|
return 0; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return 1; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _tags_middle { |
121
|
0
|
|
|
0
|
|
|
my ($self, $env) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my $messages_ar = []; |
124
|
0
|
0
|
|
|
|
|
if (exists $env->{'psgix.session'}) { |
125
|
0
|
|
|
|
|
|
my $session = Plack::Session->new($env); |
126
|
0
|
|
|
|
|
|
$messages_ar = $session->get('messages'); |
127
|
0
|
|
|
|
|
|
$session->set('messages', []); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
$self->{'_container'}->process( |
130
|
|
|
|
|
|
|
sub { |
131
|
0
|
|
|
0
|
|
|
$self->{'_login_register'}->process($messages_ar); |
132
|
|
|
|
|
|
|
}, |
133
|
0
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
return; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__END__ |