use Koha::Patron::Password::Recovery
qw(SendPasswordRecoveryEmail ValidateBorrowernumber GetValidLinkInfo CompletePasswordRecovery DeleteExpiredPasswordRecovery);
use Koha::Patrons;
-use Koha::AuthUtils qw(hash_password);
use Koha::Patrons;
my $query = new CGI;
use HTML::Entities;
$errMultipleAccountsForEmail = 1;
}
elsif ( $borrower = $search_results->next() ) { # One matching borrower
- my @emails = ( $borrower->email, $borrower->emailpro, $borrower->B_email );
+ my @emails = grep { $_ } ( $borrower->email, $borrower->emailpro, $borrower->B_email );
- my $firstNonEmptyEmail = '';
- foreach my $address ( @emails ) {
- $firstNonEmptyEmail = $address if length $address;
- last if $firstNonEmptyEmail;
- }
+ my $firstNonEmptyEmail;
+ $firstNonEmptyEmail = $emails[0] if @emails;
# Is the given email one of the borrower's ?
- if ( $email && !( grep { $_ eq $email } @emails ) ) {
+ if ( $email && !( grep /^$email$/i, @emails ) ) {
$hasError = 1;
$errNoBorrowerFound = 1;
}
DeleteExpiredPasswordRecovery( $borrower->borrowernumber );
}
}
+ # Set the $email, if we don't have one.
+ if ( !$hasError && !$email ) {
+ $email = $firstNonEmptyEmail;
+ }
}
else { # 0 matching borrower
$hasError = 1;
} elsif ( $password ne $repeatPassword ) {
$error = 'errPassNotMatch';
} else {
- my ( $is_valid, $err) = Koha::AuthUtils::is_password_valid( $password );
- unless ( $is_valid ) {
- $error = 'password_too_short' if $err eq 'too_short';
- $error = 'password_too_weak' if $err eq 'too_weak';
- $error = 'password_has_whitespaces' if $err eq 'has_whitespaces';
- } else {
- Koha::Patrons->find($borrower_number)->update_password( $username, hash_password($password) );
+ try {
+ Koha::Patrons->find($borrower_number)->set_password({ password => $password });
+
CompletePasswordRecovery($uniqueKey);
$template->param(
password_reset_done => 1,
username => $username
);
}
+ catch {
+ if ( $_->isa('Koha::Exceptions::Password::TooShort') ) {
+ $error = 'password_too_short';
+ }
+ elsif ( $_->isa('Koha::Exceptions::Password::WhitespaceCharacters') ) {
+ $error = 'password_has_whitespaces';
+ }
+ elsif ( $_->isa('Koha::Exceptions::Password::TooWeak') ) {
+ $error = 'password_too_weak';
+ }
+ };
}
if ( $error ) {
$template->param(