| 1 | package App::ZofCMS::Plugin::UserLogin::ForgotPassword; | ||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use MIME::Lite; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub _key { 'plug_user_login_forgot_password' } | ||||||||||||||||||||||||||
|
Subroutine
_key: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub _defaults { | ||||||||||||||||||||||||||
|
Subroutine
_defaults: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 16 | return ( | ||||||||||||||||||||||||||||
| 17 | 0 | dsn => "DBI:mysql:database=test;host=localhost", | |||||||||||||||||||||||||||
| 18 | user => '', | ||||||||||||||||||||||||||||
| 19 | pass => undef, | ||||||||||||||||||||||||||||
| 20 | opt => { RaiseError => 1, AutoCommit => 1 }, | ||||||||||||||||||||||||||||
| 21 | users_table => 'users', | ||||||||||||||||||||||||||||
| 22 | code_table => 'users_forgot_password', | ||||||||||||||||||||||||||||
| 23 | q_code => 'pulfp_code', | ||||||||||||||||||||||||||||
| 24 | max_abuse => '5:10:60', # 5 min intervals, max 10 attempts per 60 min. | ||||||||||||||||||||||||||||
| 25 | min_pass => 6, | ||||||||||||||||||||||||||||
| 26 | code_expiry => 24*60*60, # 1 day | ||||||||||||||||||||||||||||
| 27 | code_length => 6, | ||||||||||||||||||||||||||||
| 28 | use_stage_indicators => 1, | ||||||||||||||||||||||||||||
| 29 | subject => 'Password Reset', | ||||||||||||||||||||||||||||
| 30 | login_page => '/', | ||||||||||||||||||||||||||||
| 31 | button_send_link => q|<input type="submit" class="input_submit"| | ||||||||||||||||||||||||||||
| 32 | . q| value="Send password">|, | ||||||||||||||||||||||||||||
| 33 | button_change_pass => q|<input type="submit" class="input_submit"| | ||||||||||||||||||||||||||||
| 34 | . q| value="Change password">|, | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # email_link => undef, # this will be guessed | ||||||||||||||||||||||||||||
| 37 | # from => undef, | ||||||||||||||||||||||||||||
| 38 | # email_template => undef, # use plugin's default template | ||||||||||||||||||||||||||||
| 39 | # no_run => undef | ||||||||||||||||||||||||||||
| 40 | # create_table => undef, | ||||||||||||||||||||||||||||
| 41 | # mime_lite_params => undef, | ||||||||||||||||||||||||||||
| 42 | # email => undef, | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub _do { | ||||||||||||||||||||||||||
|
Subroutine
_do: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 47 | 0 | my ( $self, $conf, $t, $q, $config ) = @_; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | return | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if $conf->{no_run}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $self->{Q_PAGE} = ( $q->{dir} || '' ) . ( $q->{page} || '' ); | ||||||||||||||||||||||||||
|
Condition0%0/4
$q->{'dir'} || ''
$q->{'page'} || ''
MC/DC0%0/1
$q->{'dir'} || ''
$q->{'dir'}
MC/DC0%0/1
$q->{'page'} || ''
$q->{'page'}
Truth table0%0/2
A
A= $q->{'dir'}
Truth table0%0/2
A
A= $q->{'page'}
| |||||||||||||||||||||||||||||
| 53 | 0 | $self->{CONF} = $conf; | |||||||||||||||||||||||||||
| 54 | 0 | $self->{Q} = $q; | |||||||||||||||||||||||||||
| 55 | 0 | $self->{T} = $t; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | create_code_table( $conf ) | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if $conf->{create_table}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( has_value($q->{$conf->{q_code}}) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 61 | 0 | $self->process_q_code; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | elsif ( has_value($q->{pulfp_ask_link}) ) { | ||||||||||||||||||||||||||||
| 64 | 0 | $self->process_ask_link; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||
| 67 | 0 | $self->process_initial; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $t->{t}{plug_forgot_password} = $self->{OUTPUT}; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub process_q_code { | ||||||||||||||||||||||||||
|
Subroutine
process_q_code: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | 0 | my $q = $self->{Q}; | |||||||||||||||||||||||||||
| 76 | 0 | my $conf = $self->{CONF}; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | my $code = $q->{ $conf->{q_code} }; | |||||||||||||||||||||||||||
| 79 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | my $entry = ($dbh->selectall_arrayref( | ||||||||||||||||||||||||||||
| 82 | 'SELECT * FROM `' . $conf->{code_table} | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | . '` WHERE `code` = ?', | ||||||||||||||||||||||||||
|
Condition0%0/2
$dbh->selectall_arrayref('SELECT * FROM `' . $conf->{'code_table'} . '` WHERE `code` = ?', {'Slice', {}}, $code) || []
MC/DC0%0/1
$dbh->selectall_arrayref('SELECT * FROM `' . $conf->{'code_table'} . '` WHERE `code` = ?', {'Slice', {}}, $code) || []
$dbh->selectall_arrayref('SELECT * FROM `' . $conf->{'code_table'} . '` WHERE `code` = ?', {'Slice', {}}, $code)
Truth table0%0/2
A
A= $dbh->selectall_arrayref('SELECT * FROM `' . $conf->{'code_table'} . '` WHERE `code` = ?', {'Slice', {}}, $code)
| |||||||||||||||||||||||||||||
| 84 | { Slice => {} }, | ||||||||||||||||||||||||||||
| 85 | $code, | ||||||||||||||||||||||||||||
| 86 | ) || [])->[0]; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | unless ( $entry ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | $self->set_stage('code_invalid'); | |||||||||||||||||||||||||||
| 90 | 0 | $self->{OUTPUT} = '<p class="reset_code_expired">Your reset' | |||||||||||||||||||||||||||
| 91 | . ' code has expired. Please try' | ||||||||||||||||||||||||||||
| 92 | . ' resetting your password again.</p>'; | ||||||||||||||||||||||||||||
| 93 | 0 | return; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ( has_value( $q->{pulfp_has_change_pass} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $self->check_change_pass | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | or return; | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | $self->set_new_pass( $entry ); | |||||||||||||||||||||||||||
| 101 | 0 | $self->set_stage('change_pass_done'); | |||||||||||||||||||||||||||
| 102 | $self->{OUTPUT} = '<p class="reset_pass_success">Your password' | ||||||||||||||||||||||||||||
| 103 | . ' has been successfully' | ||||||||||||||||||||||||||||
| 104 | . ' changed. You can now use it to ' | ||||||||||||||||||||||||||||
| 105 | . ( | ||||||||||||||||||||||||||||
| 106 | has_value( $conf->{login_page} ) | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | ? qq| <a href="$conf->{login_page}">log in</a>| | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | : ' log in' | ||||||||||||||||||||||||||||
| 109 | ) | ||||||||||||||||||||||||||||
| 110 | .'.</p>'; | ||||||||||||||||||||||||||||
| 111 | 0 | return; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | else { | ||||||||||||||||||||||||||||
| 114 | 0 | $self->set_stage('change_pass_ask'); | |||||||||||||||||||||||||||
| 115 | 0 | $self->{OUTPUT} = $self->make_change_pass_form; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub set_new_pass { | ||||||||||||||||||||||||||
|
Subroutine
set_new_pass: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 121 | 0 | my $entry = shift; | |||||||||||||||||||||||||||
| 122 | 0 | my $q = $self->{Q}; | |||||||||||||||||||||||||||
| 123 | 0 | my $conf = $self->{CONF}; | |||||||||||||||||||||||||||
| 124 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | my $new_pass = md5_hex( $q->{pulfp_pass} ); | |||||||||||||||||||||||||||
| 127 | $dbh->do( | ||||||||||||||||||||||||||||
| 128 | 'UPDATE `' . $conf->{users_table} | ||||||||||||||||||||||||||||
| 129 | . '` SET `password` = ? WHERE `login` = ?', | ||||||||||||||||||||||||||||
| 130 | undef, | ||||||||||||||||||||||||||||
| 131 | $new_pass, | ||||||||||||||||||||||||||||
| 132 | $entry->{login}, | ||||||||||||||||||||||||||||
| 133 | 0 | ); | |||||||||||||||||||||||||||
| 134 | $dbh->do( | ||||||||||||||||||||||||||||
| 135 | 'DELETE FROM `' . $conf->{code_table} . '` WHERE `login` = ?', | ||||||||||||||||||||||||||||
| 136 | undef, | ||||||||||||||||||||||||||||
| 137 | $entry->{login}, | ||||||||||||||||||||||||||||
| 138 | 0 | ); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub check_change_pass { | ||||||||||||||||||||||||||
|
Subroutine
check_change_pass: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 143 | 0 | my $q = $self->{Q}; | |||||||||||||||||||||||||||
| 144 | 0 | my $conf = $self->{CONF}; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | my ( $pass, $repass ) = @$q{ qw/pulfp_pass pulfp_repass/ }; | |||||||||||||||||||||||||||
| 147 | 0 | ▶ | unless ( has_value( $pass ) and length $pass >= $conf->{min_pass} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
has_value($pass) and length $pass >= $conf->{"min_pass"}
MC/DC0%0/2
has_value($pass) and length $pass >= $conf->{"min_pass"}
has_value($pass)
length $pass >= $conf->{"min_pass"}
Truth table0%0/3
A and B
A= has_value($pass)B= length $pass >= $conf->{"min_pass"}
| |||||||||||||||||||||||||||||
| 148 | 0 | $self->set_stage('code_bad_pass_length'); | |||||||||||||||||||||||||||
| 149 | $self->{OUTPUT} = $self->make_change_pass_form( | ||||||||||||||||||||||||||||
| 150 | 'Your new password must be at least ' | ||||||||||||||||||||||||||||
| 151 | 0 | . $conf->{min_pass} . ' characters long.' | |||||||||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||||||||||
| 153 | 0 | return; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | unless ( has_value( $repass ) and $pass eq $repass ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
has_value($repass) and $pass eq $repass
MC/DC0%0/2
has_value($repass) and $pass eq $repass
has_value($repass)
$pass eq $repass
Truth table0%0/3
A and B
A= has_value($repass)B= $pass eq $repass
| |||||||||||||||||||||||||||||
| 157 | 0 | $self->set_stage('code_bad_pass_copy'); | |||||||||||||||||||||||||||
| 158 | 0 | $self->{OUTPUT} = $self->make_change_pass_form( | |||||||||||||||||||||||||||
| 159 | 'You did not retype your password correctly.' | ||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||
| 161 | 0 | return; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | return 1; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub make_change_pass_form { | ||||||||||||||||||||||||||
|
Subroutine
make_change_pass_form: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 168 | 0 | my ( $self, $error ) = @_; | |||||||||||||||||||||||||||
| 169 | 0 | my $q = $self->{Q}; | |||||||||||||||||||||||||||
| 170 | 0 | my $conf = $self->{CONF}; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | my $template = HTML::Template->new_scalar_ref( | |||||||||||||||||||||||||||
| 173 | \ change_pass_form_template(), | ||||||||||||||||||||||||||||
| 174 | die_on_bad_params => 0, | ||||||||||||||||||||||||||||
| 175 | ); | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | $template->param( | ||||||||||||||||||||||||||||
| 178 | submit_button => $conf->{button_change_pass}, | ||||||||||||||||||||||||||||
| 179 | page => $self->{Q_PAGE}, | ||||||||||||||||||||||||||||
| 180 | error => $error, | ||||||||||||||||||||||||||||
| 181 | code_name => $conf->{q_code}, | ||||||||||||||||||||||||||||
| 182 | code_value => $q->{ $conf->{q_code} }, | ||||||||||||||||||||||||||||
| 183 | 0 | ); | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | return $template->output; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub process_initial { | ||||||||||||||||||||||||||
|
Subroutine
process_initial: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 189 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 190 | 0 | my $show_form_error = shift; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | my $template = HTML::Template->new_scalar_ref( | |||||||||||||||||||||||||||
| 193 | \ask_login_form_template(), | ||||||||||||||||||||||||||||
| 194 | die_on_bad_params => 0, | ||||||||||||||||||||||||||||
| 195 | ); | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | $template->param( | ||||||||||||||||||||||||||||
| 198 | submit_button => $self->{CONF}{button_send_link}, | ||||||||||||||||||||||||||||
| 199 | page => $self->{Q}{page}, | ||||||||||||||||||||||||||||
| 200 | 0 | ▶ | $show_form_error ? ( error => $show_form_error ) : (), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 0 | $self->{OUTPUT} = $template->output; | |||||||||||||||||||||||||||
| 204 | 0 | $self->set_stage('initial'); | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | ▶ | sub process_ask_link { | ||||||||||||||||||||||||||
|
Subroutine
process_ask_link: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 208 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | my $q = $self->{Q}; | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | unless ( has_value( $q->{pulfp_login} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 0 | $self->set_stage('ask_error_login'); | |||||||||||||||||||||||||||
| 214 | 0 | $self->process_initial( 'Please specify your login' ); | |||||||||||||||||||||||||||
| 215 | 0 | return; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 219 | my $user = (@{ | ||||||||||||||||||||||||||||
| 220 | 0 | $dbh->selectall_arrayref( | |||||||||||||||||||||||||||
| 221 | 'SELECT * FROM `users` WHERE `login` = ?', | ||||||||||||||||||||||||||||
| 222 | { Slice => {} }, | ||||||||||||||||||||||||||||
| 223 | $q->{pulfp_login}, | ||||||||||||||||||||||||||||
| 224 | ) | ||||||||||||||||||||||||||||
| 225 | 0 | ▶ | || [] })[0]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$dbh->selectall_arrayref('SELECT * FROM `users` WHERE `login` = ?', {'Slice', {}}, $q->{'pulfp_login'}) || []
MC/DC0%0/1
$dbh->selectall_arrayref('SELECT * FROM `users` WHERE `login` = ?', {'Slice', {}}, $q->{'pulfp_login'}) || []
$dbh->selectall_arrayref('SELECT * FROM `users` WHERE `login` = ?', {'Slice', {}}, $q->{'pulfp_login'})
Truth table0%0/2
A
A= $dbh->selectall_arrayref('SELECT * FROM `users` WHERE `login` = ?', {'Slice', {}}, $q->{'pulfp_login'})
| |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | ▶ | unless ( $user ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 0 | $self->set_stage('ask_error_no_user'); | |||||||||||||||||||||||||||
| 229 | 0 | $self->process_initial( | |||||||||||||||||||||||||||
| 230 | 'The login you provided was not found in the database.' | ||||||||||||||||||||||||||||
| 231 | ); | ||||||||||||||||||||||||||||
| 232 | 0 | return; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ( $self->check_abuse( $user ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 0 | $self->set_stage('ask_error_abuse'); | |||||||||||||||||||||||||||
| 237 | 0 | $self->process_initial( | |||||||||||||||||||||||||||
| 238 | 'Sorry, but due to abuse we have to limit the amount of' | ||||||||||||||||||||||||||||
| 239 | . ' requests. Please wait a short while and try again.' | ||||||||||||||||||||||||||||
| 240 | ); | ||||||||||||||||||||||||||||
| 241 | 0 | return; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | my $code = $self->create_access_code( $user ); | |||||||||||||||||||||||||||
| 245 | 0 | $self->email_code( $user, $code ); | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | $self->set_stage('emailed'); | |||||||||||||||||||||||||||
| 248 | 0 | $self->{OUTPUT} = '<p class="reset_link_send_success">Please check' | |||||||||||||||||||||||||||
| 249 | . ' your email for further' | ||||||||||||||||||||||||||||
| 250 | . ' instructions on how to reset your password.</p>'; | ||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | ▶ | sub email_code { | ||||||||||||||||||||||||||
|
Subroutine
email_code: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 254 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 255 | 0 | my $user = shift; | |||||||||||||||||||||||||||
| 256 | 0 | my $code = shift; | |||||||||||||||||||||||||||
| 257 | 0 | my $conf = $self->{CONF}; | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | my $template = HTML::Template->new( | ||||||||||||||||||||||||||||
| 260 | die_on_bad_params => 0, | ||||||||||||||||||||||||||||
| 261 | ref $conf->{email_template} | ||||||||||||||||||||||||||||
| 262 | 0 | ▶ | ? ( filename => ${ $conf->{email_template} } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | : has_value( $conf->{email_template} ) | ||||||||||||||||||||||||||||
| 264 | ? ( scalarref => \ $conf->{email_template} ) | ||||||||||||||||||||||||||||
| 265 | 0 | ▶ | : ( scalarref => \ email_template() ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | ); | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | my $link = $conf->{email_link}; | |||||||||||||||||||||||||||
| 269 | 0 | ▶ | unless ( has_value( $link ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 0 | $link = join '', 'http://', @ENV{ qw/SERVER_NAME REQUEST_URI/ }; | |||||||||||||||||||||||||||
| 271 | 0 | ▶ | $link .= $link =~ /\?/ ? '&' : '?'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | $link .= $conf->{q_code} . '=' | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | $template->param( | ||||||||||||||||||||||||||||
| 276 | 0 | 'link' => $link . $code, | |||||||||||||||||||||||||||
| 277 | ); | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | my $msg = MIME::Lite->new ( | ||||||||||||||||||||||||||||
| 280 | Subject => $conf->{subject}, | ||||||||||||||||||||||||||||
| 281 | ( defined $conf->{from} ? ( From => $conf->{from} ) : (), ), | ||||||||||||||||||||||||||||
| 282 | To => ( | ||||||||||||||||||||||||||||
| 283 | has_value( $conf->{email} ) | ||||||||||||||||||||||||||||
| 284 | ? $conf->{email} | ||||||||||||||||||||||||||||
| 285 | : $user->{email} | ||||||||||||||||||||||||||||
| 286 | 0 | ▶ | ), | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 287 | Type => 'text/html', | ||||||||||||||||||||||||||||
| 288 | Data => $template->output, | ||||||||||||||||||||||||||||
| 289 | ); | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 0 | MIME::Lite->send( @{ $conf->{mime_lite_params} } ) | |||||||||||||||||||||||||||
| 292 | 0 | ▶ | if $conf->{mime_lite_params}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 0 | $msg->send; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | ▶ | sub create_access_code { | ||||||||||||||||||||||||||
|
Subroutine
create_access_code: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 298 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 299 | 0 | my $user = shift; | |||||||||||||||||||||||||||
| 300 | 0 | my $conf = $self->{CONF}; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 0 | my @chars = ( 0 .. 9, 'a'..'z', 'A'..'Z' ); | |||||||||||||||||||||||||||
| 303 | 0 | my $code = ''; | |||||||||||||||||||||||||||
| 304 | 0 | for ( 0 .. $conf->{code_length} ) { | |||||||||||||||||||||||||||
| 305 | 0 | $code .= $chars[ rand @chars ]; | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | # delete old entries | ||||||||||||||||||||||||||||
| 311 | $dbh->do( | ||||||||||||||||||||||||||||
| 312 | 'DELETE FROM `' . $conf->{code_table} | ||||||||||||||||||||||||||||
| 313 | . '` WHERE `time` < ?', | ||||||||||||||||||||||||||||
| 314 | undef, | ||||||||||||||||||||||||||||
| 315 | time() - $conf->{code_expiry}, | ||||||||||||||||||||||||||||
| 316 | 0 | ); | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | $dbh->do( | ||||||||||||||||||||||||||||
| 319 | 'INSERT INTO `' . $conf->{code_table} | ||||||||||||||||||||||||||||
| 320 | . '` (`login`, `time`, `code`) VALUES (?, ?, ?)', | ||||||||||||||||||||||||||||
| 321 | undef, | ||||||||||||||||||||||||||||
| 322 | $user->{login}, | ||||||||||||||||||||||||||||
| 323 | 0 | time(), | |||||||||||||||||||||||||||
| 324 | $code, | ||||||||||||||||||||||||||||
| 325 | ); | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | return $code; | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 0 | ▶ | sub check_abuse { | ||||||||||||||||||||||||||
|
Subroutine
check_abuse: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 331 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 332 | 0 | my $user = shift; | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | my $max_abuse = $self->{CONF}{max_abuse} | ||||||||||||||||||||||||||||
| 335 | 0 | ▶ | or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | $max_abuse =~ /^\d+:\d+:\d+$/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | or die 'Invalid value for `max_abuse` parameter in' | ||||||||||||||||||||||||||||
| 339 | . ' UserLogin::ForgotPassword plugin; must' | ||||||||||||||||||||||||||||
| 340 | . ' match qr/^\d+:\d+:\d+$/.'; | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 0 | my ( $interval, $attempts, $period ) = split /:/, $max_abuse; | |||||||||||||||||||||||||||
| 343 | 0 | my $dbh = $self->dbh; | |||||||||||||||||||||||||||
| 344 | my $previous_tries = $dbh->selectall_arrayref( | ||||||||||||||||||||||||||||
| 345 | 'SELECT * FROM `' . $self->{CONF}{code_table} | ||||||||||||||||||||||||||||
| 346 | . '` WHERE `login` = ? AND `time` > ?' | ||||||||||||||||||||||||||||
| 347 | . ' ORDER BY `time`+0 DESC', | ||||||||||||||||||||||||||||
| 348 | { Slice => {} }, | ||||||||||||||||||||||||||||
| 349 | $user->{login}, | ||||||||||||||||||||||||||||
| 350 | 0 | ▶ | time() - $period*60, | ||||||||||||||||||||||||||
|
Condition0%0/2
$dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'code_table'} . '` WHERE `login` = ? AND `time` > ?' . ' ORDER BY `time`+0 DESC', {'Slice', {}}, $user->{'login'}, time - $period * 60) || []
MC/DC0%0/1
$dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'code_table'} . '` WHERE `login` = ? AND `time` > ?' . ' ORDER BY `time`+0 DESC', {'Slice', {}}, $user->{'login'}, time - $period * 60) || []
$dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'code_table'} . '` WHERE `login` = ? AND `time` > ?' . ' ORDER BY `time`+0 DESC', {'Slice', {}}, $user->{'login'}, time - $period * 60)
Truth table0%0/2
A
A= $dbh->selectall_arrayref('SELECT * FROM `' . $self->{'CONF'}{'code_table'} . '` WHERE `login` = ? AND `time` > ?' . ' ORDER BY `time`+0 DESC', {'Slice', {}}, $user->{'login'}, time - $period * 60)
| |||||||||||||||||||||||||||||
| 351 | ) || []; | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | ▶ | return 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | if @$previous_tries > $attempts; | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | return 1 | ||||||||||||||||||||||||||||
| 357 | if @$previous_tries | ||||||||||||||||||||||||||||
| 358 | 0 | ▶ | and $previous_tries->[0]{time} > time() - $interval*60; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$previous_tries and $previous_tries->[0]{"time"} > time - $interval * 60
MC/DC0%0/2
@$previous_tries and $previous_tries->[0]{"time"} > time - $interval * 60
@$previous_tries
$previous_tries->[0]{"time"} > time - $interval * 60
Truth table0%0/3
A and B
A= @$previous_triesB= $previous_tries->[0]{"time"} > time - $interval * 60
| |||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 0 | return 0; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | ▶ | sub set_stage { | ||||||||||||||||||||||||||
|
Subroutine
set_stage: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 364 | 0 | my ( $self, $stage ) = @_; | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | $self->{T}{t}{"plug_forgot_password_stage_$stage"} = 1 | ||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if $self->{CONF}{use_stage_indicators}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 0 | ▶ | sub dbh { | ||||||||||||||||||||||||||
|
Subroutine
dbh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 371 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | return $self->{DBH} | ||||||||||||||||||||||||||||
| 374 | 0 | ▶ | if $self->{DBH}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | $self->{DBH} = DBI->connect_cached( | ||||||||||||||||||||||||||||
| 377 | 0 | @{ $self->{CONF} }{ qw/dsn user pass opt/ }, | |||||||||||||||||||||||||||
| 378 | ); | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 0 | return $self->{DBH}; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 0 | ▶ | sub has_value { | ||||||||||||||||||||||||||
|
Subroutine
has_value: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 384 | 0 | my $v = shift; | |||||||||||||||||||||||||||
| 385 | 0 | ▶ | return 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $v and length $v
MC/DC0%0/2
defined $v and length $v
defined $v
length $v
Truth table0%0/3
A and B
A= defined $vB= length $v
| |||||||||||||||||||||||||||||
| 386 | if defined $v and length $v; | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 0 | return 0; | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 0 | ▶ | sub create_code_table { | ||||||||||||||||||||||||||
|
Subroutine
create_code_table: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 392 | 0 | my $conf = shift; | |||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | my $dbh = DBI->connect_cached( | ||||||||||||||||||||||||||||
| 395 | 0 | @$conf{ qw/dsn user pass opt/ }, | |||||||||||||||||||||||||||
| 396 | ); | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | $dbh->do( | ||||||||||||||||||||||||||||
| 399 | 0 | 'CREATE TABLE `' . $conf->{code_table} . '` ( | |||||||||||||||||||||||||||
| 400 | `login` TEXT, | ||||||||||||||||||||||||||||
| 401 | `time` VARCHAR(10), | ||||||||||||||||||||||||||||
| 402 | `code` TEXT | ||||||||||||||||||||||||||||
| 403 | );' | ||||||||||||||||||||||||||||
| 404 | ); | ||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 0 | ▶ | sub change_pass_form_template { | ||||||||||||||||||||||||||
|
Subroutine
change_pass_form_template: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 408 | 0 | return <<'END_HTML'; | |||||||||||||||||||||||||||
| 409 | <form action="" method="POST" id="plug_forgot_password_new_pass_form"> | ||||||||||||||||||||||||||||
| 410 | <div> | ||||||||||||||||||||||||||||
| 411 | <p>Please enter your new password.</p> | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | <input type="hidden" name="page" value="<tmpl_var escape='html' | ||||||||||||||||||||||||||||
| 414 | name='page'>"> | ||||||||||||||||||||||||||||
| 415 | <input type="hidden" name="<tmpl_var escape='html' name='code_name'>" | ||||||||||||||||||||||||||||
| 416 | value="<tmpl_var escape='html' name='code_value'>"> | ||||||||||||||||||||||||||||
| 417 | <input type="hidden" name="pulfp_has_change_pass" value="1"> | ||||||||||||||||||||||||||||
| 418 | <tmpl_if name='error'> | ||||||||||||||||||||||||||||
| 419 | <p class="error"><tmpl_var escape='html' name='error'></p> | ||||||||||||||||||||||||||||
| 420 | </tmpl_if> | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | <ul> | ||||||||||||||||||||||||||||
| 423 | <li> | ||||||||||||||||||||||||||||
| 424 | <label for="pulfp_pass">New password: </label | ||||||||||||||||||||||||||||
| 425 | ><input type="password" | ||||||||||||||||||||||||||||
| 426 | class="input_password" | ||||||||||||||||||||||||||||
| 427 | name="pulfp_pass" | ||||||||||||||||||||||||||||
| 428 | id="pulfp_pass"> | ||||||||||||||||||||||||||||
| 429 | </li> | ||||||||||||||||||||||||||||
| 430 | <li> | ||||||||||||||||||||||||||||
| 431 | <label for="pulfp_repass">Retype new password: </label | ||||||||||||||||||||||||||||
| 432 | ><input type="password" | ||||||||||||||||||||||||||||
| 433 | class="input_password" | ||||||||||||||||||||||||||||
| 434 | name="pulfp_repass" | ||||||||||||||||||||||||||||
| 435 | id="pulfp_repass"> | ||||||||||||||||||||||||||||
| 436 | </li> | ||||||||||||||||||||||||||||
| 437 | </ul> | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | <tmpl_var name="submit_button"> | ||||||||||||||||||||||||||||
| 440 | </div> | ||||||||||||||||||||||||||||
| 441 | </form> | ||||||||||||||||||||||||||||
| 442 | END_HTML | ||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 0 | ▶ | sub email_template { | ||||||||||||||||||||||||||
|
Subroutine
email_template: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 446 | 0 | return <<'END_EMAIL_HTML'; | |||||||||||||||||||||||||||
| 447 | <h2>Password Reset</h2> | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | <p>Hello. Someone (possibly you) requested a password reset. If that | ||||||||||||||||||||||||||||
| 450 | was you, please follow this link to complete the action: | ||||||||||||||||||||||||||||
| 451 | <a href="<tmpl_var escape='html' name='link'>"><tmpl_var escape='html' | ||||||||||||||||||||||||||||
| 452 | name='link'></a></p> | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | <p>If you did not request anything, simply ignore this email.</p> | ||||||||||||||||||||||||||||
| 455 | END_EMAIL_HTML | ||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 0 | ▶ | sub ask_login_form_template { | ||||||||||||||||||||||||||
|
Subroutine
ask_login_form_template: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 459 | 0 | return <<'END_FORM'; | |||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | <form action="" method="POST" id="plug_forgot_password_form"> | ||||||||||||||||||||||||||||
| 462 | <div> | ||||||||||||||||||||||||||||
| 463 | <p>Please enter your login into the form below and an email with | ||||||||||||||||||||||||||||
| 464 | further instructions will be sent to you.</p> | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | <input type="hidden" name="page" value="<tmpl_var escape='html' | ||||||||||||||||||||||||||||
| 467 | name='page'>"> | ||||||||||||||||||||||||||||
| 468 | <input type="hidden" name="pulfp_ask_link" value="1"> | ||||||||||||||||||||||||||||
| 469 | <tmpl_if name='error'> | ||||||||||||||||||||||||||||
| 470 | <p class="error"><tmpl_var escape='html' name='error'></p> | ||||||||||||||||||||||||||||
| 471 | </tmpl_if> | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | <label for="pulfp_login">Your login: </label | ||||||||||||||||||||||||||||
| 474 | ><input type="text" | ||||||||||||||||||||||||||||
| 475 | class="input_text" | ||||||||||||||||||||||||||||
| 476 | name="pulfp_login" | ||||||||||||||||||||||||||||
| 477 | id="pulfp_login"> | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | <tmpl_var name="submit_button"> | ||||||||||||||||||||||||||||
| 480 | </div> | ||||||||||||||||||||||||||||
| 481 | </form> | ||||||||||||||||||||||||||||
| 482 | END_FORM | ||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 1 | 1; | |||||||||||||||||||||||||||
| 486 | __END__ | ||||||||||||||||||||||||||||