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

(-)a/Koha/Patron/Password/Recovery.pm (-2 / +19 lines)
Lines 65-75 sub ValidateBorrowernumber { Link Here
65
        },
65
        },
66
        { columns => 'borrowernumber' }
66
        { columns => 'borrowernumber' }
67
    );
67
    );
68
69
    if ( $rs->next ) {
68
    if ( $rs->next ) {
70
        return 1;
69
        return 1;
71
    }
70
    }
72
71
    DeleteExpiredPasswordRecovery($borrower_number);
73
    return 0;
72
    return 0;
74
}
73
}
75
74
Lines 180-185 sub CompletePasswordRecovery { Link Here
180
    return $entry->delete();
179
    return $entry->delete();
181
}
180
}
182
181
182
=head2 DeleteExpiredPasswordRecovery
183
184
    $bool = DeleteExpiredPasswordRecovery($borrowernumber) 
185
186
    Deletes an expired password recovery entry.
187
188
=cut
189
190
sub DeleteExpiredPasswordRecovery {
191
    my $borrower_number = shift;
192
    my $model =
193
      Koha::Database->new->schema->resultset('BorrowerPasswordRecovery');
194
    my $entry = $model->search(
195
        { -or => [ borrowernumber => $borrower_number ] } );
196
    return $entry->delete();
197
}
198
199
183
END { }    # module clean-up code here (global destructor)
200
END { }    # module clean-up code here (global destructor)
184
201
185
1;
202
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