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