@@ -, +, @@ - Apply this patch - Run: $ git grep update_password - Sign off :-D --- Koha/Patron.pm | 31 +------------------------------ t/db_dependent/Koha/Patrons.t | 27 +-------------------------- 2 files changed, 2 insertions(+), 56 deletions(-) --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -276,7 +276,7 @@ sub store { $self->userid($stored_userid); } - # Password must be updated using $self->update_password + # Password must be updated using $self->set_password $self->password($self_from_storage->password); if ( C4::Context->preference('FeeOnChangePatronCategory') @@ -639,35 +639,6 @@ sub is_going_to_expire { return 0; } -=head3 update_password - -my $updated = $patron->update_password( $userid, $password ); - -Update the userid and the password of a patron. -If the userid already exists, returns and let DBIx::Class warns -This will add an entry to action_logs if BorrowersLog is set. - -=cut - -sub update_password { - my ( $self, $userid, $password ) = @_; - eval { $self->userid($userid)->store; }; - return if $@; # Make sure the userid is not already in used by another patron - - return 0 if $password eq '****' or $password eq ''; - - my $digest = Koha::AuthUtils::hash_password($password); - $self->update( - { - password => $digest, - login_attempts => 0, - } - ); - - logaction( "MEMBERS", "CHANGE PASS", $self->borrowernumber, "" ) if C4::Context->preference("BorrowersLog"); - return $digest; -} - =head3 set_password $patron->set_password({ password => $plain_text_password [, skip_validation => 1 ] }); --- a/t/db_dependent/Koha/Patrons.t +++ a/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 34; +use Test::More tests => 33; use Test::Warn; use Test::Exception; use Test::MockModule; @@ -208,31 +208,6 @@ subtest 'has_overdues' => sub { $issue->delete(); }; -subtest 'update_password' => sub { - plan tests => 7; - - t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); - my $original_userid = $new_patron_1->userid; - my $original_password = $new_patron_1->password; - warning_like { $retrieved_patron_1->update_password( $new_patron_2->userid, 'another_password' ) } - qr{Duplicate entry}, - 'Koha::Patron->update_password should warn if the userid is already used by another patron'; - is( Koha::Patrons->find( $new_patron_1->borrowernumber )->userid, $original_userid, 'Koha::Patron->update_password should not have updated the userid' ); - is( Koha::Patrons->find( $new_patron_1->borrowernumber )->password, $original_password, 'Koha::Patron->update_password should not have updated the userid' ); - - my $digest = $retrieved_patron_1->update_password( 'another_nonexistent_userid_1', 'another_password' ); - is( Koha::Patrons->find( $new_patron_1->borrowernumber )->userid, 'another_nonexistent_userid_1', 'Koha::Patron->update_password should have updated the userid' ); - is( Koha::Patrons->find( $new_patron_1->borrowernumber )->password, $digest, 'Koha::Patron->update_password should have updated the password' ); - - my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $new_patron_1->borrowernumber } )->count; - is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->update_password should have logged' ); - - t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); - $retrieved_patron_1->update_password( 'yet_another_nonexistent_userid_1', 'another_password' ); - $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $new_patron_1->borrowernumber } )->count; - is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->update_password should not have logged' ); -}; - subtest 'is_expired' => sub { plan tests => 4; my $patron = $builder->build({ source => 'Borrower' }); --