ZofCMS/Plugin/UserLogin/ChangePassword.pm

filter: Statementstmt 35.0% 20 / 57 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 6 / 12 Podpod n/a totaltotal 27.3% 26 / 95 CC 12 SCAR 36.7
CC
12
Cov
25%
_do
90.0
_make_form
20.0
_key
2.0
CRAP 39.3
« ZofCMS/Plugin/BasicLWP.pm ↑ Summary ZofCMS/Plugin/LinkifyText.pm »
1 package App::ZofCMS::Plugin::UserLogin::ChangePassword;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.001010'; # VERSION
7  
8 1 ▶use base 'App::ZofCMS::Plugin::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Digest::MD5 (qw/md5_hex/);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use HTML::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub _key { 'plug_user_login_change_password' }
Subroutine _key: not called CC=1 SCAR=6.9
14 0 ▶sub _defaults {
Subroutine _defaults: not called CC=1 SCAR=6.9
15 dsn => "DBI:mysql:database=test;host=localhost",
16 user => 'test',
17 pass => 'test',
18 opt => { RaiseError => 1, AutoCommit => 1 },
19 table => 'users',
20 0 ▶ login => sub { $_[0]{d}{user}{login} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 key => 'change_pass_form',
22 min => 4,
23 submit_button => q|<input type="submit" class="input_submit"|
24 . q| name="plug_user_login_change_password_submit"|
25 . q| value="Change password">|,
26 }
27 0 ▶sub _do {
Subroutine _do: not called CC=9 SCAR=45.0
28 0 my ( $self, $conf, $t, $q, $config ) = @_;
29  
30 0 ▶ unless ( $q->{plug_user_login_change_password_submit} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($q->{"plug_user_login_change_password_submit"}) 0 0 0
31 0 $t->{t}{ $conf->{key} } = _make_form($q, undef, $conf);
32 0 return;
33 }
34  
35 my $dbh = DBI->connect_cached(
36 0 @$conf{ qw/dsn user pass opt/ },
37 );
38  
39 $conf->{login} = $conf->{login}->( $t, $q, $config )
40 0 ▶ if ref $conf->{login} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $conf->{"login"} eq "CODE" 0 0 0
41  
42 my $pass = ( ( $dbh->selectall_arrayref(
43 "SELECT `password` FROM `$conf->{table}` WHERE `login` = ?",
44 { Slice => {} },
45 $conf->{login},
46 0 ▶ ) || [] )->[0] || {} )->{password};
Condition0%0/4
+($dbh->selectall_arrayref("SELECT `password` FROM `$conf->{'table'}` WHERE `login` = ?", {'Slice', {}}, $conf->{'login'}) || [])->[0] || {}
l!l
00
$dbh->selectall_arrayref("SELECT `password` FROM `$conf->{'table'}` WHERE `login` = ?", {'Slice', {}}, $conf->{'login'}) || []
l!l
00
MC/DC0%0/1
+($dbh->selectall_arrayref("SELECT `password` FROM `$conf->{'table'}` WHERE `login` = ?", {'Slice', {}}, $conf->{'login'}) || [])->[0] || {}
$dbh->selectall_arrayref("SELECT `password` FROM `$conf->{'table'}` WHERE `login` = ?", {'Slice', {}}, $conf->{'login'})
Truth table0%0/2
A
A= $dbh->selectall_arrayref("SELECT `password` FROM `$conf->{'table'}` WHERE `login` = ?", {'Slice', {}}, $conf->{'login'})
Aresult
11
00
47  
48 0 ▶ unless ( defined $pass ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pass) 0 0 0
49 0 $t->{t}{ $conf->{key} } = _make_form($q, $t, $conf, 'Your login was not found');
50 0 return;
51 }
52  
53 0 ▶ unless ( $pass eq md5_hex( $q->{plug_user_login_change_password_pass} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pass eq md5_hex($q->{"plug_user_login_change_password_pass"})) 0 0 0
54 0 $t->{t}{ $conf->{key} } = _make_form($q, $t, $conf, 'Invalid current password');
55 0 return;
56 }
57  
58 0 ▶ if ( $q->{plug_user_login_change_password_newpass}
Branch: 1 branch
BranchTrueFalseTotal
if ($q->{"plug_user_login_change_password_newpass"} ne $q->{"plug_user_login_change_password_repass"}) 0 0 0
59 ne $q->{plug_user_login_change_password_repass}
60 ) {
61 0 $t->{t}{ $conf->{key} } = _make_form($q, $t, $conf, 'You did not retype your new password correctly');
62 0 return;
63 }
64  
65 0 ▶ if ( $conf->{min} > length $q->{plug_user_login_change_password_newpass} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"min"} > length $q->{"plug_user_login_change_password_newpass"}) 0 0 0
66 0 $t->{t}{ $conf->{key} } = _make_form($q, $t, $conf, "New password must be at least $conf->{min} characters in length");
67 0 return;
68 }
69  
70 $dbh->do(
71 "UPDATE `$conf->{table}` SET `password` = ? WHERE `login` = ?",
72 undef,
73 md5_hex( $q->{plug_user_login_change_password_newpass} ),
74 $conf->{login},
75 0 );
76  
77 0 $t->{t}{ $conf->{key} } = _make_form($q, $t, $conf);
78 }
79  
80  
81 0 ▶sub _make_form {
Subroutine _make_form: not called CC=4 SCAR=30.0
82 0 my ( $q, $t, $conf, $error ) = @_;
83  
84 0 my $temp = HTML::Template->new_scalar_ref( \ _form_template() );
85  
86 $temp->param(
87 dir => $q->{dir},
88 page => $q->{page},
89 submit_button => $conf->{submit_button},
90 0 );
91  
92 0 ▶ unless ( defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 0 0 0
93 0 return $temp->output;
94 }
95  
96 0 ▶ if ( defined $error and length $error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error and length $error) 0 0 0
Condition0%0/3
defined $error and length $error
!ll&&!rl&&r
000
MC/DC0%0/2
defined $error and length $error
defined $error length $error
Truth table0%0/3
A and B
A= defined $errorB= length $error
ABresult
0X0
100
111
97 0 $t->{t}{plug_user_login_change_password_error} = 1;
98 0 $temp->param( error => $error );
99 0 return $temp->output;
100 }
101  
102 0 $t->{t}{plug_user_login_change_password_ok} = 1;
103 0 $temp->param( change_ok => 1 );
104 0 return $temp->output;
105 }
106  
107 0 ▶sub _form_template {
Subroutine _form_template: not called CC=1 SCAR=6.9
108 0 return <<'END';
109 <tmpl_if name='change_ok'>
110 <p id="plug_user_login_change_password_ok" class="success-message">Your password has been successfully changed</p>
111 <tmpl_else>
112 <form action="" method="POST" id="plug_user_login_change_password_form">
113 <div>
114 <tmpl_if name='error'>
115 <p class="error"><tmpl_var escape='html' name='error'></p>
116 </tmpl_if>
117 <input type="hidden" name="page" value="<tmpl_var escape='html' name='page'>">
118 <input type="hidden" name="dir" value="<tmpl_var escape='html' name='dir'>">
119 <ul>
120 <li>
121 <label for="plug_user_login_change_password_pass">Current password: </label
122 ><input type="password" class="input_password" name="plug_user_login_change_password_pass" id="plug_user_login_change_password_pass">
123 </li>
124 <li>
125 <label for="plug_user_login_change_password_newpass">New password: </label
126 ><input type="password" class="input_password" name="plug_user_login_change_password_newpass" id="plug_user_login_change_password_newpass">
127 </li>
128 <li>
129 <label for="plug_user_login_change_password_repass">Retype new password: </label
130 ><input type="password" class="input_password" name="plug_user_login_change_password_repass" id="plug_user_login_change_password_repass">
131 </li>
132 </ul>
133 <tmpl_var name='submit_button'>
134 </div>
135 </form>
136 </tmpl_if>
137 END
138 }
139  
140 1 1;
141 __END__
« ZofCMS/Plugin/BasicLWP.pm ↑ Summary ZofCMS/Plugin/LinkifyText.pm »