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