View | Details | Raw Unified | Return to bug 18025
Collapse All | Expand All

(-)a/Koha/Patron/Password/Recovery.pm (-2 / +19 lines)
Lines 32-37 BEGIN { Link Here
32
      &SendPasswordRecoveryEmail
32
      &SendPasswordRecoveryEmail
33
      &GetValidLinkInfo
33
      &GetValidLinkInfo
34
      &CompletePasswordRecovery
34
      &CompletePasswordRecovery
35
      &DeleteExpiredPasswordRecovery
35
    );
36
    );
36
}
37
}
37
38
Lines 66-76 sub ValidateBorrowernumber { Link Here
66
        },
67
        },
67
        { columns => 'borrowernumber' }
68
        { columns => 'borrowernumber' }
68
    );
69
    );
69
70
    if ( $rs->next ) {
70
    if ( $rs->next ) {
71
        return 1;
71
        return 1;
72
    }
72
    }
73
74
    return 0;
73
    return 0;
75
}
74
}
76
75
Lines 181-186 sub CompletePasswordRecovery { Link Here
181
    return $entry->delete();
180
    return $entry->delete();
182
}
181
}
183
182
183
=head2 DeleteExpiredPasswordRecovery
184
185
    $bool = DeleteExpiredPasswordRecovery($borrowernumber) 
186
187
    Deletes an expired password recovery entry.
188
189
=cut
190
191
sub DeleteExpiredPasswordRecovery {
192
    my $borrower_number = shift;
193
    my $model =
194
      Koha::Database->new->schema->resultset('BorrowerPasswordRecovery');
195
    my $entry = $model->search(
196
        { borrowernumber => $borrower_number } );
197
    return $entry->delete();
198
}
199
200
184
END { }    # module clean-up code here (global destructor)
201
END { }    # module clean-up code here (global destructor)
185
202
186
1;
203
1;
(-)a/opac/opac-password-recovery.pl (-1 / +6 lines)
Lines 8-14 use C4::Koha; Link Here
8
use C4::Output;
8
use C4::Output;
9
use C4::Context;
9
use C4::Context;
10
use Koha::Patron::Password::Recovery
10
use Koha::Patron::Password::Recovery
11
  qw(SendPasswordRecoveryEmail ValidateBorrowernumber GetValidLinkInfo CompletePasswordRecovery);
11
  qw(SendPasswordRecoveryEmail ValidateBorrowernumber GetValidLinkInfo CompletePasswordRecovery DeleteExpiredPasswordRecovery);
12
use Koha::Patrons;
12
use Koha::Patrons;
13
use Koha::AuthUtils qw(hash_password);
13
use Koha::AuthUtils qw(hash_password);
14
use Koha::Patrons;
14
use Koha::Patrons;
Lines 96-101 if ( $query->param('sendEmail') || $query->param('resendEmail') ) { Link Here
96
            $hasError                = 1;
96
            $hasError                = 1;
97
            $errAlreadyStartRecovery = 1;
97
            $errAlreadyStartRecovery = 1;
98
        }
98
        }
99
        elsif ( !ValidateBorrowernumber($borrower->borrowernumber) 
100
            && !$query->param('resendEmail') )
101
        {
102
            DeleteExpiredPasswordRecovery($borrower->borrowernumber);
103
        }
99
    }
104
    }
100
    else {    # 0 matching borrower
105
    else {    # 0 matching borrower
101
        $hasError           = 1;
106
        $hasError           = 1;
(-)a/t/db_dependent/Passwordrecovery.t (-3 / +41 lines)
Lines 22-28 use C4::Letters; Link Here
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Patrons;
23
use Koha::Patrons;
24
24
25
use Test::More tests => 16;
25
use Test::More tests => 18;
26
26
27
use_ok('Koha::Patron::Password::Recovery');
27
use_ok('Koha::Patron::Password::Recovery');
28
28
Lines 38-49 $dbh->{RaiseError} = 1; Link Here
38
38
39
my $borrowernumber1 = '2000000000';
39
my $borrowernumber1 = '2000000000';
40
my $borrowernumber2 = '2000000001';
40
my $borrowernumber2 = '2000000001';
41
my $borrowernumber3 = '2000000002';
41
my $userid1 = "I83MFItzRpGPxD3vW0";
42
my $userid1 = "I83MFItzRpGPxD3vW0";
42
my $userid2 = "Gh5t43980hfSAOcvne";
43
my $userid2 = "Gh5t43980hfSAOcvne";
44
my $userid3 = "adsfada80hfSAOcvne";
43
my $email1  = $userid1 . '@koha-community.org';
45
my $email1  = $userid1 . '@koha-community.org';
44
my $email2  = $userid2 . '@koha-community.org';
46
my $email2  = $userid2 . '@koha-community.org';
47
my $email3  = $userid3 . '@koha-community.org';
45
my $uuid1   = "ABCD1234";
48
my $uuid1   = "ABCD1234";
46
my $uuid2   = "WXYZ0987";
49
my $uuid2   = "WXYZ0987";
50
my $uuid3   = "LMNO4561";
47
51
48
my $categorycode = 'S'; #  staff
52
my $categorycode = 'S'; #  staff
49
my $branch       = $schema->resultset('Branch')->first(); #  legit branch from your db
53
my $branch       = $schema->resultset('Branch')->first(); #  legit branch from your db
Lines 74-79 $schema->resultset('Borrower')->create( Link Here
74
        branchcode      => $branch,
78
        branchcode      => $branch,
75
    }
79
    }
76
);
80
);
81
$schema->resultset('Borrower')->create(
82
    {
83
        borrowernumber => $borrowernumber3,
84
        surname        => '',
85
        address        => '',
86
        city           => '',
87
        userid         => $userid3,
88
        email          => $email3,
89
        categorycode   => $categorycode,
90
        branchcode     => $branch,
91
    }
92
);
77
93
78
$schema->resultset('BorrowerPasswordRecovery')->create(
94
$schema->resultset('BorrowerPasswordRecovery')->create(
79
    {
95
    {
Lines 89-94 $schema->resultset('BorrowerPasswordRecovery')->create( Link Here
89
        valid_until    => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 2 )->datetime()
105
        valid_until    => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 2 )->datetime()
90
    }
106
    }
91
);
107
);
108
$schema->resultset('BorrowerPasswordRecovery')->create(
109
    {
110
        borrowernumber => $borrowernumber3,
111
        uuid           => $uuid3,
112
        valid_until    => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 3 )->datetime()
113
    }
114
);
115
92
116
93
can_ok( "Koha::Patron::Password::Recovery", qw(ValidateBorrowernumber GetValidLinkInfo SendPasswordRecoveryEmail CompletePasswordRecovery) );
117
can_ok( "Koha::Patron::Password::Recovery", qw(ValidateBorrowernumber GetValidLinkInfo SendPasswordRecoveryEmail CompletePasswordRecovery) );
94
118
Lines 117-123 ok( ! defined($bnum3), "[GetValidLinkInfo] Invalid UUID returns no borrowernumbe Link Here
117
# Koha::Patron::Password::Recovery::CompletePasswordRecovery #
141
# Koha::Patron::Password::Recovery::CompletePasswordRecovery #
118
##############################################################
142
##############################################################
119
143
120
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid1) == 2, "[CompletePasswordRecovery] Completing a password recovery deletes the entry and expired entries" );
144
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid1) == 2, "[CompletePasswordRecovery] Completing a password recovery deletes the used entry" );
121
145
122
$schema->resultset('BorrowerPasswordRecovery')->create(
146
$schema->resultset('BorrowerPasswordRecovery')->create(
123
    {
147
    {
Lines 130-135 $schema->resultset('BorrowerPasswordRecovery')->create( Link Here
130
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid2) == 1, "[CompletePasswordRecovery] An expired or invalid UUID purges expired entries" );
154
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid2) == 1, "[CompletePasswordRecovery] An expired or invalid UUID purges expired entries" );
131
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid2) == 0, "[CompletePasswordRecovery] Returns 0 on a clean table" );
155
ok( Koha::Patron::Password::Recovery::CompletePasswordRecovery($uuid2) == 0, "[CompletePasswordRecovery] Returns 0 on a clean table" );
132
156
157
###################################################################
158
# Koha::Patron::Password::Recovery::DeleteExpiredPasswordRecovery #
159
###################################################################
160
161
$schema->resultset('BorrowerPasswordRecovery')->create(
162
    {   
163
        borrowernumber => $borrowernumber3,
164
        uuid           => $uuid3,
165
        valid_until    => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 3 )->datetime()
166
    }   
167
);
168
169
ok( Koha::Patron::Password::Recovery::DeleteExpiredPasswordRecovery($borrowernumber3) == 1, "[DeleteExpiredPasswordRecovery] we can delete the unused entry" );
170
ok( Koha::Patron::Password::Recovery::DeleteExpiredPasswordRecovery($borrowernumber3) == 0, "[DeleteExpiredPasswordRecovery] Returns 0 on a clean table" );
171
133
###############################################################
172
###############################################################
134
# Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail #
173
# Koha::Patron::Password::Recovery::SendPasswordRecoveryEmail #
135
###############################################################
174
###############################################################
136
- 

Return to bug 18025